Skip to content

Commit 63e719f

Browse files
Disallow rename/copy/delete on unshared files (#40540)
Release Notes: - Disallow rename/delete/copy on unshared files Co-Authored-By: Cole <[email protected]>
1 parent 1e69e5d commit 63e719f

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

crates/project/src/worktree_store.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
sync::{Arc, atomic::AtomicUsize},
66
};
77

8-
use anyhow::{Context as _, Result, anyhow};
8+
use anyhow::{Context as _, Result, anyhow, bail};
99
use collections::{HashMap, HashSet};
1010
use fs::{Fs, copy_recursive};
1111
use futures::{
@@ -1203,6 +1203,16 @@ impl WorktreeStore {
12031203
RelPath::from_proto(&envelope.payload.new_path)?,
12041204
);
12051205
let (scan_id, entry) = this.update(&mut cx, |this, cx| {
1206+
let Some((_, project_id)) = this.downstream_client else {
1207+
bail!("no downstream client")
1208+
};
1209+
let Some(entry) = this.entry_for_id(entry_id, cx) else {
1210+
bail!("no such entry");
1211+
};
1212+
if entry.is_private && project_id != REMOTE_SERVER_PROJECT_ID {
1213+
bail!("entry is private")
1214+
}
1215+
12061216
let new_worktree = this
12071217
.worktree_for_id(new_worktree_id, cx)
12081218
.context("no such worktree")?;
@@ -1226,6 +1236,15 @@ impl WorktreeStore {
12261236
) -> Result<proto::ProjectEntryResponse> {
12271237
let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id);
12281238
let worktree = this.update(&mut cx, |this, cx| {
1239+
let Some((_, project_id)) = this.downstream_client else {
1240+
bail!("no downstream client")
1241+
};
1242+
let Some(entry) = this.entry_for_id(entry_id, cx) else {
1243+
bail!("no entry")
1244+
};
1245+
if entry.is_private && project_id != REMOTE_SERVER_PROJECT_ID {
1246+
bail!("entry is private")
1247+
}
12291248
this.worktree_for_entry(entry_id, cx)
12301249
.context("worktree not found")
12311250
})??;
@@ -1246,6 +1265,18 @@ impl WorktreeStore {
12461265
let worktree = this
12471266
.worktree_for_entry(entry_id, cx)
12481267
.context("no such worktree")?;
1268+
1269+
let Some((_, project_id)) = this.downstream_client else {
1270+
bail!("no downstream client")
1271+
};
1272+
let entry = worktree
1273+
.read(cx)
1274+
.entry_for_id(entry_id)
1275+
.ok_or_else(|| anyhow!("missing entry"))?;
1276+
if entry.is_private && project_id != REMOTE_SERVER_PROJECT_ID {
1277+
bail!("entry is private")
1278+
}
1279+
12491280
let scan_id = worktree.read(cx).scan_id();
12501281
anyhow::Ok((
12511282
scan_id,

crates/project_panel/src/project_panel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use workspace::{
6464
DraggedSelection, OpenInTerminal, OpenOptions, OpenVisible, PreviewTabsSettings, SelectedEntry,
6565
SplitDirection, Workspace,
6666
dock::{DockPosition, Panel, PanelEvent},
67-
notifications::{DetachAndPromptErr, NotifyTaskExt},
67+
notifications::{DetachAndPromptErr, NotifyResultExt, NotifyTaskExt},
6868
};
6969
use worktree::CreatedEntry;
7070
use zed_actions::workspace::OpenWithSystem;
@@ -2677,12 +2677,14 @@ impl ProjectPanel {
26772677
for task in paste_tasks {
26782678
match task {
26792679
PasteTask::Rename(task) => {
2680-
if let Some(CreatedEntry::Included(entry)) = task.await.log_err() {
2680+
if let Some(CreatedEntry::Included(entry)) =
2681+
task.await.notify_async_err(cx)
2682+
{
26812683
last_succeed = Some(entry);
26822684
}
26832685
}
26842686
PasteTask::Copy(task) => {
2685-
if let Some(Some(entry)) = task.await.log_err() {
2687+
if let Some(Some(entry)) = task.await.notify_async_err(cx) {
26862688
last_succeed = Some(entry);
26872689
}
26882690
}

0 commit comments

Comments
 (0)