Skip to content

Commit ec078aa

Browse files
committed
auto_update: дозволити використання локальних архівів віддаленого
сервера Додати можливість використовувати локально упаковані архіви віддаленого сервера замість обов'язкового завантаження через мережу. Це вирішує проблему помилок підключення на збірках, які не опубліковані в офіційному репозиторії. - Додано пошук локального архіву за шляхом із системної змінної оточення `ZED_REMOTE_SERVER_PATH`, у теці з виконуваним файлом або у системній теці застосунку. - Налаштовано автоматичне пакування сервера під час збирання проєкту для Linux.
1 parent 49188a9 commit ec078aa

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎crates/auto_update/src/auto_update.rs‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,41 @@ impl std::error::Error for MissingDependencyError {}
4747
const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60);
4848
const NIGHTLY_POLL_INTERVAL: Duration = Duration::from_secs(15 * 60);
4949
const REMOTE_SERVER_CACHE_LIMIT: usize = 5;
50+
const REMOTE_SERVER_PATH_ENV: &str = "ZED_REMOTE_SERVER_PATH";
51+
52+
/// Looks for a remote server archive that ships with this build instead of one served by
53+
/// the release API. Builds whose version is not published upstream have no asset to fetch,
54+
/// so without a local archive every remote connection fails with a 404 from the API.
55+
///
56+
/// The archive is handed to the transports as-is: they upload it and unpack it on the
57+
/// remote, so it must stay compressed (`.gz`, or `.zip` for Windows remotes), exactly as
58+
/// `script/bundle-linux` produces it.
59+
async fn bundled_remote_server_archive(os: &str, arch: &str) -> Option<PathBuf> {
60+
let extension = if os == "windows" { "zip" } else { "gz" };
61+
let file_name = format!("zed-remote-server-{os}-{arch}.{extension}");
62+
63+
let mut candidates = Vec::new();
64+
if let Some(configured_path) = env::var_os(REMOTE_SERVER_PATH_ENV) {
65+
let configured_path = PathBuf::from(configured_path);
66+
candidates.push(configured_path.join(&file_name));
67+
candidates.push(configured_path);
68+
}
69+
if let Ok(executable_path) = env::current_exe()
70+
&& let Some(executable_dir) = executable_path.parent()
71+
{
72+
candidates.push(executable_dir.join(&file_name));
73+
}
74+
candidates.push(remote_servers_dir().join(&file_name));
75+
76+
for candidate in candidates {
77+
if let Ok(metadata) = smol::fs::metadata(&candidate).await
78+
&& metadata.is_file()
79+
{
80+
return Some(candidate);
81+
}
82+
}
83+
None
84+
}
5085

5186
#[cfg(target_os = "linux")]
5287
fn linux_rsync_install_hint() -> &'static str {
@@ -569,6 +604,15 @@ impl AutoUpdater {
569604
set_status: impl Fn(&str, &mut AsyncApp) + Send + 'static,
570605
cx: &mut AsyncApp,
571606
) -> Result<PathBuf> {
607+
if let Some(bundled_path) = bundled_remote_server_archive(os, arch).await {
608+
log::info!(
609+
"using bundled remote server archive at {}",
610+
bundled_path.display()
611+
);
612+
set_status("Using bundled remote server", cx);
613+
return Ok(bundled_path);
614+
}
615+
572616
let this = cx.update(|cx| {
573617
cx.default_global::<GlobalAutoUpdate>()
574618
.0
@@ -625,6 +669,13 @@ impl AutoUpdater {
625669
arch: &str,
626670
cx: &mut AsyncApp,
627671
) -> Result<Option<String>> {
672+
// Returning `None` makes the transports fall back to
673+
// `download_remote_server_release`, which serves the bundled archive. Asking the
674+
// release API here instead would abort the connection before that fallback runs.
675+
if bundled_remote_server_archive(os, arch).await.is_some() {
676+
return Ok(None);
677+
}
678+
628679
let this = cx.update(|cx| {
629680
cx.default_global::<GlobalAutoUpdate>()
630681
.0

‎script/bundle-linux‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,17 @@ chmod +x "${zed_dir}/share/applications/$APP_ID.desktop"
195195
# Copy generated licenses so they'll end up in archive too
196196
cp "assets/licenses.md" "${zed_dir}/licenses.md"
197197

198-
# Create archive out of everything that's in the temp directory
199198
arch=$(uname -m)
199+
200+
# Remote server. The copy next to zed-editor is what the app uploads to a remote host, so
201+
# it has to be in place before the tarball is created.
202+
gzip -f --stdout --best "${target_dir}/${remote_server_triple}/release/remote_server" > "${target_dir}/zed-remote-server-linux-${arch}.gz"
203+
cp "${target_dir}/zed-remote-server-linux-${arch}.gz" "${zed_dir}/libexec/zed-remote-server-linux-${arch}.gz"
204+
205+
# Create archive out of everything that's in the temp directory
200206
archive="zed-linux-${arch}.tar.gz"
201207

202208
rm -rf "${archive}"
203209
remove_match="zed(-[a-zA-Z0-9]+)?-linux-$(uname -m)\.tar\.gz"
204210
ls "${target_dir}/release" | grep -E ${remove_match} | xargs -d "\n" -I {} rm -f "${target_dir}/release/{}" || true
205211
tar -czvf "${target_dir}/release/$archive" -C ${temp_dir} "zed$suffix.app"
206-
207-
gzip -f --stdout --best "${target_dir}/${remote_server_triple}/release/remote_server" > "${target_dir}/zed-remote-server-linux-${arch}.gz"

0 commit comments

Comments
 (0)