Always use strings to represent paths over the wire
Previously, the protocol used a mix of strings and bytes without any consistency. When we go to multiple platforms, we won't be able to mix encodings of paths anyway. We don't know this is the right approach, but it at least makes things consistent and easy to read in the database, on the wire, etc. Really, we should be using entry ids etc to refer to entries on the wire anyway, but there's a chance this is the wrong decision. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
974ef967a3
commit
4b1dcf2d55
7 changed files with 32 additions and 35 deletions
|
@ -44,12 +44,10 @@ use std::{
|
|||
cell::RefCell,
|
||||
cmp::{self, Ordering},
|
||||
convert::TryInto,
|
||||
ffi::OsString,
|
||||
hash::Hash,
|
||||
mem,
|
||||
num::NonZeroU32,
|
||||
ops::Range,
|
||||
os::unix::{ffi::OsStrExt, prelude::OsStringExt},
|
||||
path::{Component, Path, PathBuf},
|
||||
rc::Rc,
|
||||
str,
|
||||
|
@ -837,7 +835,7 @@ impl Project {
|
|||
.request(proto::CreateProjectEntry {
|
||||
worktree_id: project_path.worktree_id.to_proto(),
|
||||
project_id,
|
||||
path: project_path.path.as_os_str().as_bytes().to_vec(),
|
||||
path: project_path.path.to_string_lossy().into(),
|
||||
is_directory,
|
||||
})
|
||||
.await?;
|
||||
|
@ -881,7 +879,7 @@ impl Project {
|
|||
.request(proto::CopyProjectEntry {
|
||||
project_id,
|
||||
entry_id: entry_id.to_proto(),
|
||||
new_path: new_path.as_os_str().as_bytes().to_vec(),
|
||||
new_path: new_path.to_string_lossy().into(),
|
||||
})
|
||||
.await?;
|
||||
let entry = response
|
||||
|
@ -924,7 +922,7 @@ impl Project {
|
|||
.request(proto::RenameProjectEntry {
|
||||
project_id,
|
||||
entry_id: entry_id.to_proto(),
|
||||
new_path: new_path.as_os_str().as_bytes().to_vec(),
|
||||
new_path: new_path.to_string_lossy().into(),
|
||||
})
|
||||
.await?;
|
||||
let entry = response
|
||||
|
@ -4606,7 +4604,7 @@ impl Project {
|
|||
let entry = worktree
|
||||
.update(&mut cx, |worktree, cx| {
|
||||
let worktree = worktree.as_local_mut().unwrap();
|
||||
let path = PathBuf::from(OsString::from_vec(envelope.payload.path));
|
||||
let path = PathBuf::from(envelope.payload.path);
|
||||
worktree.create_entry(path, envelope.payload.is_directory, cx)
|
||||
})
|
||||
.await?;
|
||||
|
@ -4630,7 +4628,7 @@ impl Project {
|
|||
let worktree_scan_id = worktree.read_with(&cx, |worktree, _| worktree.scan_id());
|
||||
let entry = worktree
|
||||
.update(&mut cx, |worktree, cx| {
|
||||
let new_path = PathBuf::from(OsString::from_vec(envelope.payload.new_path));
|
||||
let new_path = PathBuf::from(envelope.payload.new_path);
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
|
@ -4658,7 +4656,7 @@ impl Project {
|
|||
let worktree_scan_id = worktree.read_with(&cx, |worktree, _| worktree.scan_id());
|
||||
let entry = worktree
|
||||
.update(&mut cx, |worktree, cx| {
|
||||
let new_path = PathBuf::from(OsString::from_vec(envelope.payload.new_path));
|
||||
let new_path = PathBuf::from(envelope.payload.new_path);
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
|
|
|
@ -2166,7 +2166,11 @@ async fn test_rescan_and_remote_updates(
|
|||
proto::WorktreeMetadata {
|
||||
id: initial_snapshot.id().to_proto(),
|
||||
root_name: initial_snapshot.root_name().into(),
|
||||
abs_path: initial_snapshot.abs_path().as_os_str().as_bytes().to_vec(),
|
||||
abs_path: initial_snapshot
|
||||
.abs_path()
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into(),
|
||||
visible: true,
|
||||
},
|
||||
rpc.clone(),
|
||||
|
|
|
@ -40,7 +40,6 @@ use std::{
|
|||
future::Future,
|
||||
mem,
|
||||
ops::{Deref, DerefMut},
|
||||
os::unix::prelude::{OsStrExt, OsStringExt},
|
||||
path::{Path, PathBuf},
|
||||
sync::{atomic::AtomicUsize, Arc},
|
||||
task::Poll,
|
||||
|
@ -221,7 +220,7 @@ impl Worktree {
|
|||
let root_name = worktree.root_name.clone();
|
||||
let visible = worktree.visible;
|
||||
|
||||
let abs_path = PathBuf::from(OsString::from_vec(worktree.abs_path));
|
||||
let abs_path = PathBuf::from(worktree.abs_path);
|
||||
let snapshot = Snapshot {
|
||||
id: WorktreeId(remote_id as usize),
|
||||
abs_path: Arc::from(abs_path.deref()),
|
||||
|
@ -656,7 +655,7 @@ impl LocalWorktree {
|
|||
id: self.id().to_proto(),
|
||||
root_name: self.root_name().to_string(),
|
||||
visible: self.visible,
|
||||
abs_path: self.abs_path().as_os_str().as_bytes().to_vec(),
|
||||
abs_path: self.abs_path().as_os_str().to_string_lossy().into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -990,7 +989,7 @@ impl LocalWorktree {
|
|||
let update = proto::UpdateWorktree {
|
||||
project_id,
|
||||
worktree_id,
|
||||
abs_path: snapshot.abs_path().as_os_str().as_bytes().to_vec(),
|
||||
abs_path: snapshot.abs_path().to_string_lossy().into(),
|
||||
root_name: snapshot.root_name().to_string(),
|
||||
updated_entries: snapshot
|
||||
.entries_by_path
|
||||
|
@ -1381,7 +1380,7 @@ impl LocalSnapshot {
|
|||
proto::UpdateWorktree {
|
||||
project_id,
|
||||
worktree_id: self.id().to_proto(),
|
||||
abs_path: self.abs_path().as_os_str().as_bytes().to_vec(),
|
||||
abs_path: self.abs_path().to_string_lossy().into(),
|
||||
root_name,
|
||||
updated_entries: self.entries_by_path.iter().map(Into::into).collect(),
|
||||
removed_entries: Default::default(),
|
||||
|
@ -1449,7 +1448,7 @@ impl LocalSnapshot {
|
|||
proto::UpdateWorktree {
|
||||
project_id,
|
||||
worktree_id,
|
||||
abs_path: self.abs_path().as_os_str().as_bytes().to_vec(),
|
||||
abs_path: self.abs_path().to_string_lossy().into(),
|
||||
root_name: self.root_name().to_string(),
|
||||
updated_entries,
|
||||
removed_entries,
|
||||
|
@ -2928,7 +2927,7 @@ impl<'a> From<&'a Entry> for proto::Entry {
|
|||
Self {
|
||||
id: entry.id.to_proto(),
|
||||
is_dir: entry.is_dir(),
|
||||
path: entry.path.as_os_str().as_bytes().to_vec(),
|
||||
path: entry.path.to_string_lossy().into(),
|
||||
inode: entry.inode,
|
||||
mtime: Some(entry.mtime.into()),
|
||||
is_symlink: entry.is_symlink,
|
||||
|
@ -2946,14 +2945,10 @@ impl<'a> TryFrom<(&'a CharBag, proto::Entry)> for Entry {
|
|||
EntryKind::Dir
|
||||
} else {
|
||||
let mut char_bag = *root_char_bag;
|
||||
char_bag.extend(
|
||||
String::from_utf8_lossy(&entry.path)
|
||||
.chars()
|
||||
.map(|c| c.to_ascii_lowercase()),
|
||||
);
|
||||
char_bag.extend(entry.path.chars().map(|c| c.to_ascii_lowercase()));
|
||||
EntryKind::File(char_bag)
|
||||
};
|
||||
let path: Arc<Path> = PathBuf::from(OsString::from_vec(entry.path)).into();
|
||||
let path: Arc<Path> = PathBuf::from(entry.path).into();
|
||||
Ok(Entry {
|
||||
id: ProjectEntryId::from_proto(entry.id),
|
||||
kind,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue