Skip to content

Commit 1a8d50e

Browse files
munessclaude
andcommitted
Add legacy symlink for backwards compatibility
Creates ~/.bottle/state.json as a symlink pointing to the active bottle's state file (bottles/<name>/state.json). This maintains backwards compatibility for scripts that read the old path. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2ad2b34 commit 1a8d50e

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

src/manifest/state.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl BottleState {
9999
std::fs::read_to_string(path).ok().map(|s| s.trim().to_string())
100100
}
101101

102-
/// Set the active bottle
102+
/// Set the active bottle (also updates legacy symlink for backwards compatibility)
103103
pub fn set_active(bottle: &str) -> std::io::Result<()> {
104104
let path = Self::active_path().ok_or_else(|| {
105105
std::io::Error::new(std::io::ErrorKind::NotFound, "Could not determine home directory")
@@ -109,7 +109,42 @@ impl BottleState {
109109
std::fs::create_dir_all(parent)?;
110110
}
111111

112-
std::fs::write(path, bottle)
112+
std::fs::write(&path, bottle)?;
113+
114+
// Update legacy symlink (~/.bottle/state.json -> bottles/<name>/state.json)
115+
// for backwards compatibility with scripts reading the old path
116+
Self::update_legacy_symlink(bottle)?;
117+
118+
Ok(())
119+
}
120+
121+
/// Update the legacy state.json symlink to point to the active bottle's state
122+
#[cfg(unix)]
123+
fn update_legacy_symlink(bottle: &str) -> std::io::Result<()> {
124+
use std::os::unix::fs::symlink;
125+
126+
let legacy_path = Self::bottle_dir()
127+
.map(|d| d.join("state.json"))
128+
.ok_or_else(|| {
129+
std::io::Error::new(std::io::ErrorKind::NotFound, "Could not determine home directory")
130+
})?;
131+
132+
// Target is relative: bottles/<name>/state.json
133+
let target = PathBuf::from("bottles").join(bottle).join("state.json");
134+
135+
// Remove existing file/symlink if present
136+
let _ = std::fs::remove_file(&legacy_path);
137+
138+
// Create symlink (ignore errors - this is optional backwards compat)
139+
let _ = symlink(&target, &legacy_path);
140+
141+
Ok(())
142+
}
143+
144+
#[cfg(not(unix))]
145+
fn update_legacy_symlink(_bottle: &str) -> std::io::Result<()> {
146+
// Symlinks require elevated privileges on Windows, skip for now
147+
Ok(())
113148
}
114149

115150
/// Load state for the active bottle

0 commit comments

Comments
 (0)