mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-29 20:22:13 +01:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3f6f0b155 | ||
|
|
4e96ae8c61 | ||
|
|
bba74b5e65 | ||
|
|
fd0fb66448 | ||
|
|
7d963b3dd7 | ||
|
|
5647b8e684 | ||
|
|
b6ce90fcd5 | ||
|
|
7614ed6731 | ||
|
|
c44c1bccb5 |
No files matched your search
@@ -19,7 +19,7 @@ impl Core {
|
||||
if is_local_uid_str(&op.uid) {
|
||||
match self.withdrawn_twin(op)? {
|
||||
Some(twin) => {
|
||||
self.writes.hide(&twin);
|
||||
self.withdraw_landed(&twin);
|
||||
match self
|
||||
.block_on_bounded(self.drive.trash_nodes(std::slice::from_ref(&twin)))
|
||||
.and_then(batch::into_unit)
|
||||
@@ -67,6 +67,21 @@ impl Core {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Take a node a withdrawn create made on Drive out of every listing.
|
||||
///
|
||||
/// Hiding keeps it out of listings from now on, not out of one taken while
|
||||
/// Drive listed it and the drain still waited for the answer. A file made
|
||||
/// under the name then opened the node being trashed, and every write to
|
||||
/// it was refused with EACCES (`docs/BUGS.md` B303).
|
||||
fn withdraw_landed(&self, uid: &NodeUid) {
|
||||
self.writes.hide(uid);
|
||||
self.for_each_mount(|st, notify| {
|
||||
if let Some((parent, name)) = st.forget_or_unlink(uid) {
|
||||
notify.inval_entry(parent, name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Remove a trash op that landed, and the blob of a create it withdrew.
|
||||
pub(crate) fn retire_trash_op(
|
||||
&self,
|
||||
@@ -191,7 +206,7 @@ impl Core {
|
||||
real: &NodeUid,
|
||||
name: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
self.writes.hide(real);
|
||||
self.withdraw_landed(real);
|
||||
self.note_self_change(real);
|
||||
let trash = PendingOp {
|
||||
id: trash,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::*;
|
||||
use pdfs_vfs::files::Files;
|
||||
use pdfs_vfs::namespace::Namespace;
|
||||
use pdfs_vfs::namespace::{Namespace, Renamed};
|
||||
use pdfs_vfs::open::{DirListing, dir_page};
|
||||
|
||||
impl Filesystem for ProtonFs {
|
||||
@@ -1225,308 +1225,31 @@ impl ProtonFs {
|
||||
flags: RenameFlags,
|
||||
reply: ReplyEmpty,
|
||||
) {
|
||||
if let Err(error) = self
|
||||
.core
|
||||
.require_writable(parent)
|
||||
.and_then(|()| self.core.require_writable(newparent))
|
||||
let flags = pdfs_vfs::namespace::RenameFlags {
|
||||
no_replace: flags.contains(RenameFlags::RENAME_NOREPLACE),
|
||||
exchange: flags.contains(RenameFlags::RENAME_EXCHANGE),
|
||||
};
|
||||
match self
|
||||
.namespace
|
||||
.rename(parent, name, newparent, newname, flags)
|
||||
{
|
||||
reply.error(error);
|
||||
return;
|
||||
}
|
||||
let (ino, mut uid) = match self.core.lookup_child(parent, name) {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
reply.error(e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
// Ancestor cycle check: moving a directory into itself or one of its descendants is forbidden by POSIX (EINVAL).
|
||||
{
|
||||
let st = self.core.state();
|
||||
if let Some(entry) = st.entries.get(&ino)
|
||||
&& entry.node.is_folder()
|
||||
&& st.is_ancestor_of(ino, newparent)
|
||||
{
|
||||
reply.error(Errno::EINVAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The destination has to be listed either way: the queued path pushes
|
||||
// the node into that listing, and the online one drops it to force a
|
||||
// re-enumeration.
|
||||
if newparent != parent
|
||||
&& let Err(e) = self.core.ensure_children(newparent)
|
||||
{
|
||||
reply.error(e);
|
||||
return;
|
||||
}
|
||||
let (old_parent_uid, new_parent_uid) = {
|
||||
let st = self.core.state();
|
||||
match (st.entries.get(&parent), st.entries.get(&newparent)) {
|
||||
(Some(old), Some(new)) => (old.uid.clone(), new.uid.clone()),
|
||||
_ => {
|
||||
reply.error(Errno::ENOENT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
// `rename(2)` replaces an existing destination; Proton has no replacing
|
||||
// rename, so the victim has to be removed first and the operation stops
|
||||
// being atomic. Without this the 422 surfaced as a blanket EIO and every
|
||||
// write-to-temp-then-rename tool — rsync, atomic editor saves — failed
|
||||
// at the very end of its transfer (`docs/BUGS.md` B13).
|
||||
//
|
||||
// `RENAME_EXCHANGE` has no Proton primitive and cannot be emulated
|
||||
// without a window in which one of the two names does not exist.
|
||||
if flags.contains(RenameFlags::RENAME_EXCHANGE) {
|
||||
reply.error(Errno::EINVAL);
|
||||
return;
|
||||
}
|
||||
let victim = match self.core.lookup_child(newparent, newname) {
|
||||
// Renaming a node onto its own name is a no-op, never a self-replace.
|
||||
Ok((_, vuid)) if vuid == uid => None,
|
||||
Ok(x) => Some(x),
|
||||
// Nothing to replace: the overwhelmingly common case.
|
||||
Err(e) if e.code() == libc::ENOENT => None,
|
||||
Err(e) => {
|
||||
reply.error(e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
// Written before the victim is removed and ended when this returns, so
|
||||
// a stop in between is settled on the next start (`docs/BUGS.md` B302).
|
||||
let mut _journal: Option<ReplaceJournal> = None;
|
||||
let replacement_authorized = if let Some((victim_ino, victim_uid)) = &victim {
|
||||
if flags.contains(RenameFlags::RENAME_NOREPLACE) {
|
||||
reply.error(Errno::EEXIST);
|
||||
return;
|
||||
}
|
||||
// POSIX requires both ends to agree on being a directory, and the
|
||||
// check has to happen before anything is trashed: getting it wrong
|
||||
// turns a refusal into the destruction of the destination.
|
||||
let (src_dir, dst_dir) = {
|
||||
let st = self.core.state();
|
||||
let is_dir = |i: &u64| {
|
||||
st.entries
|
||||
.get(i)
|
||||
.map(|e| matches!(e.node.kind, NodeKind::Folder))
|
||||
};
|
||||
match (is_dir(&ino), is_dir(victim_ino)) {
|
||||
(Some(a), Some(b)) => (a, b),
|
||||
_ => {
|
||||
reply.error(Errno::ENOENT);
|
||||
return;
|
||||
Ok(Renamed::Done) => reply.ok(),
|
||||
Ok(Renamed::Queued) => {
|
||||
// Answer first: the kernel updates its cache while it
|
||||
// processes the answer, and an invalidation sent before it
|
||||
// would be overwritten, leaving an empty destination listing.
|
||||
reply.ok();
|
||||
if let Some(notifier) = self.core.session.notifier.get() {
|
||||
let _ = notifier.inval_entry(parent, OsStr::new(name));
|
||||
let _ = notifier.inval_entry(newparent, OsStr::new(newname));
|
||||
let _ = notifier.inval_inode(parent);
|
||||
if newparent != parent {
|
||||
let _ = notifier.inval_inode(newparent);
|
||||
}
|
||||
}
|
||||
};
|
||||
// Replacing a directory means trashing it, and Proton trashes a
|
||||
// folder with its whole subtree — so the destination's emptiness has
|
||||
// to be known before the decision is made.
|
||||
let dst_empty = if dst_dir {
|
||||
if let Err(e) = self.core.ensure_children(*victim_ino) {
|
||||
reply.error(e);
|
||||
return;
|
||||
}
|
||||
self.core
|
||||
.state
|
||||
.lock()
|
||||
.children
|
||||
.get(victim_ino)
|
||||
.is_none_or(|kids| kids.is_empty())
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if let Err(e) = check_replaceable(src_dir, dst_dir, dst_empty) {
|
||||
reply.error(e);
|
||||
return;
|
||||
}
|
||||
if let Err(error) = require_rename_access(
|
||||
|authority| self.core.require_uid_writable(authority),
|
||||
&uid,
|
||||
&old_parent_uid,
|
||||
&new_parent_uid,
|
||||
) {
|
||||
reply.error(error);
|
||||
return;
|
||||
}
|
||||
match ReplaceJournal::begin(&self.core.db, &uid, victim_uid, &new_parent_uid, newname) {
|
||||
Ok(journal) => _journal = Some(journal),
|
||||
Err(error) => {
|
||||
error!(%uid, %error, "recording a replacing rename failed; refusing it");
|
||||
reply.error(Errno::EIO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Err(e) = self.core.remove_replaced(*victim_ino, victim_uid, newname) {
|
||||
reply.error(e);
|
||||
return;
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
// A node whose own creation is still queued has no server-side identity
|
||||
// to rename: the queued op *is* the node, so rewriting its target is the
|
||||
// whole rename. Nothing reaches the API, which is why this works offline.
|
||||
// A create that lands meanwhile leaves no op to rewrite; the node is
|
||||
// then renamed by the uid Drive gave it (docs/BUGS.md B142).
|
||||
if is_local_uid(&uid) {
|
||||
match self.core.db.rewrite_op_target(
|
||||
&uid.to_string(),
|
||||
&new_parent_uid.to_string(),
|
||||
newname,
|
||||
) {
|
||||
Ok(true) => {
|
||||
self.core
|
||||
.state()
|
||||
.rename_in_place(ino, newparent, &new_parent_uid, newname);
|
||||
// A create that failed on its old name is due again.
|
||||
self.core.wake_drain();
|
||||
// Finalize: a transient scratch file (its create parked, bytes
|
||||
// held back) renamed to a finished name is the moment the
|
||||
// completed file is meant to reach Drive. Un-park the create so
|
||||
// the drain uploads it once (docs/BUGS.md B70). Renaming to
|
||||
// another transient name leaves it parked.
|
||||
if is_transient_name(name) && !is_transient_name(newname) {
|
||||
match self.core.db.set_create_hold(&uid.to_string(), false) {
|
||||
Ok(_) => {
|
||||
self.core.wake_drain();
|
||||
debug!(%uid, newname, "un-parked a finalized transient create");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(%uid, error = %e, "un-parking a finalized transient create failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
debug!(%uid, newname, "renamed a node whose create is still queued");
|
||||
reply.ok();
|
||||
return;
|
||||
}
|
||||
Ok(false) => match self.core.landed_row_uid(ino) {
|
||||
Some(real) => {
|
||||
debug!(local = %uid, %real, newname, "create landed under a rename");
|
||||
uid = real;
|
||||
}
|
||||
None => {
|
||||
warn!(%uid, name, newname, "queued create vanished under a rename");
|
||||
self.core
|
||||
.restore_replaced(victim.as_ref(), &new_parent_uid, newname);
|
||||
reply.error(Errno::EBUSY);
|
||||
return;
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
error!(%uid, error = %e, "rewriting a queued create's target failed");
|
||||
self.core
|
||||
.restore_replaced(victim.as_ref(), &new_parent_uid, newname);
|
||||
reply.error(Errno::EIO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Err(error) => reply.error(namespace_errno(error)),
|
||||
}
|
||||
// Offline, or into a folder that does not exist remotely yet: queue the
|
||||
// rename rather than 404 or fail. Online moves into a real parent still
|
||||
// take the synchronous path, so a genuine API refusal (permissions, a
|
||||
// name clash) surfaces to the caller instead of becoming a queued op
|
||||
// that can only ever conflict.
|
||||
// The queued rename, as a closure: the network going away under the
|
||||
// synchronous path below lands here too, with whatever half already
|
||||
// reached Drive. The op records the end state, so the drain finishes
|
||||
// the rest.
|
||||
let queue_it = |reply: ReplyEmpty| {
|
||||
let queued = if replacement_authorized {
|
||||
self.core.queue_rename_authorized(
|
||||
ino,
|
||||
&uid,
|
||||
&old_parent_uid,
|
||||
newparent,
|
||||
&new_parent_uid,
|
||||
newname,
|
||||
)
|
||||
} else {
|
||||
self.core.queue_rename(
|
||||
ino,
|
||||
&uid,
|
||||
&old_parent_uid,
|
||||
newparent,
|
||||
&new_parent_uid,
|
||||
newname,
|
||||
)
|
||||
};
|
||||
match queued {
|
||||
Ok(()) => {
|
||||
// Send the rename response first. Kernel-side rename cache
|
||||
// updates happen while processing that response; notifying
|
||||
// before it lets those updates overwrite our invalidation
|
||||
// and retain an empty destination readdir page.
|
||||
reply.ok();
|
||||
if let Some(notifier) = self.core.session.notifier.get() {
|
||||
let _ = notifier.inval_entry(parent, OsStr::new(&name));
|
||||
let _ = notifier.inval_entry(newparent, OsStr::new(&newname));
|
||||
let _ = notifier.inval_inode(parent);
|
||||
if newparent != parent {
|
||||
let _ = notifier.inval_inode(newparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
self.core
|
||||
.restore_replaced(victim.as_ref(), &new_parent_uid, newname);
|
||||
reply.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
if rename_needs_queue(
|
||||
self.core.sends_inline(),
|
||||
is_local_uid(&new_parent_uid),
|
||||
newparent != parent,
|
||||
newname != name,
|
||||
) {
|
||||
queue_it(reply);
|
||||
return;
|
||||
}
|
||||
// A failure past this point has already trashed any node the rename was
|
||||
// replacing, so put it back rather than leaving the caller with neither
|
||||
// the source moved nor the destination intact.
|
||||
if let Err(error) = require_rename_access(
|
||||
|authority| self.core.require_uid_writable(authority),
|
||||
&uid,
|
||||
&old_parent_uid,
|
||||
&new_parent_uid,
|
||||
) {
|
||||
self.core
|
||||
.restore_replaced(victim.as_ref(), &new_parent_uid, newname);
|
||||
reply.error(error);
|
||||
return;
|
||||
}
|
||||
// A move that also renames is one request, so the name only has to be
|
||||
// free in the destination, and the reply never stands for half of it.
|
||||
let renamed = if newparent != parent {
|
||||
let target = (newname != name).then_some(newname);
|
||||
self.core.move_rename_remote(&uid, &new_parent_uid, target)
|
||||
} else if newname != name {
|
||||
self.core.rename_remote(&uid, newname)
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
if let Err(e) = renamed {
|
||||
if self.core.lost_link(&e, "rename") {
|
||||
queue_it(reply);
|
||||
return;
|
||||
}
|
||||
error!(%uid, error = %e, "rename failed");
|
||||
self.core
|
||||
.restore_replaced(victim.as_ref(), &new_parent_uid, newname);
|
||||
reply.error(Errno::EIO);
|
||||
return;
|
||||
}
|
||||
// Through the guard, so the database has both folders unlisted before
|
||||
// the reply. The next lookup rebuilds a folder still marked listed from
|
||||
// the database, which did not have the move yet (docs/BUGS.md B135).
|
||||
self.core
|
||||
.state()
|
||||
.relocate(ino, parent, newparent, &new_parent_uid, newname);
|
||||
reply.ok();
|
||||
}
|
||||
|
||||
/// Answer with an inode's current attributes, or `ENOENT` if it went away
|
||||
@@ -1621,42 +1344,3 @@ impl ProtonFs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A replacing rename's journal entry, ended when the rename returns, however
|
||||
/// it returns. Only a stop leaves it behind, and that is what it is for.
|
||||
struct ReplaceJournal {
|
||||
db: Arc<Db>,
|
||||
source: String,
|
||||
}
|
||||
|
||||
impl ReplaceJournal {
|
||||
fn begin(
|
||||
db: &Arc<Db>,
|
||||
source: &NodeUid,
|
||||
victim: &NodeUid,
|
||||
new_parent: &NodeUid,
|
||||
new_name: &str,
|
||||
) -> pdfs_core::Result<Self> {
|
||||
let source = source.to_string();
|
||||
db.begin_replace(&pdfs_store::db::ReplaceIntent {
|
||||
source_uid: source.clone(),
|
||||
victim_uid: victim.to_string(),
|
||||
new_parent_uid: new_parent.to_string(),
|
||||
new_name: new_name.to_owned(),
|
||||
started_ms: now_millis(),
|
||||
run: 0,
|
||||
})?;
|
||||
Ok(Self {
|
||||
db: db.clone(),
|
||||
source,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ReplaceJournal {
|
||||
fn drop(&mut self) {
|
||||
if let Err(error) = self.db.end_replace(&self.source) {
|
||||
warn!(source = %self.source, %error, "ending a replacing rename's journal entry failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
+91
-51
@@ -361,15 +361,6 @@ fn fuse_name(name: &OsStr) -> Result<String, Errno> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether a `rename` may replace an existing destination, as an errno.
|
||||
fn check_replaceable(src_dir: bool, dst_dir: bool, dst_empty: bool) -> Result<(), Errno> {
|
||||
pdfs_vfs::names::check_replaceable(src_dir, dst_dir, dst_empty).map_err(|error| match error {
|
||||
pdfs_vfs::names::ReplaceError::IsDirectory => Errno::EISDIR,
|
||||
pdfs_vfs::names::ReplaceError::NotDirectory => Errno::ENOTDIR,
|
||||
pdfs_vfs::names::ReplaceError::NotEmpty => Errno::ENOTEMPTY,
|
||||
})
|
||||
}
|
||||
|
||||
/// The errno the kernel gets for an operation the open-file service refused.
|
||||
fn file_errno(error: pdfs_vfs::files::FileError<Errno>) -> Errno {
|
||||
use pdfs_vfs::files::FileError;
|
||||
@@ -445,6 +436,9 @@ fn namespace_errno(error: pdfs_vfs::namespace::NamespaceError<Errno>) -> Errno {
|
||||
NamespaceError::IsDirectory => Errno::EISDIR,
|
||||
NamespaceError::NotDirectory => Errno::ENOTDIR,
|
||||
NamespaceError::NotEmpty => Errno::ENOTEMPTY,
|
||||
NamespaceError::InvalidArgument => Errno::EINVAL,
|
||||
NamespaceError::Exists => Errno::EEXIST,
|
||||
NamespaceError::Busy => Errno::EBUSY,
|
||||
NamespaceError::Io => Errno::EIO,
|
||||
NamespaceError::Host(errno) => errno,
|
||||
}
|
||||
@@ -465,8 +459,12 @@ impl pdfs_vfs::namespace::NamespaceHost for Core {
|
||||
Core::ensure_children(self, ino)
|
||||
}
|
||||
|
||||
fn lookup_child(&self, parent: u64, name: &str) -> Result<(u64, NodeUid), Errno> {
|
||||
Core::lookup_child(self, parent, name)
|
||||
fn lookup_child(&self, parent: u64, name: &str) -> Result<Option<(u64, NodeUid)>, Errno> {
|
||||
match Core::lookup_child(self, parent, name) {
|
||||
Ok(found) => Ok(Some(found)),
|
||||
Err(e) if e == Errno::ENOENT => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn sends_inline(&self) -> bool {
|
||||
@@ -550,6 +548,71 @@ impl pdfs_vfs::namespace::NamespaceHost for Core {
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_replaced(&self, ino: u64, uid: &NodeUid, name: &str) -> Result<(), Errno> {
|
||||
Core::remove_replaced(self, ino, uid, name)
|
||||
}
|
||||
|
||||
fn restore_replaced(&self, victim: Option<&(u64, NodeUid)>, parent: &NodeUid, name: &str) {
|
||||
Core::restore_replaced(self, victim, parent, name);
|
||||
}
|
||||
|
||||
fn queue_rename(
|
||||
&self,
|
||||
ino: u64,
|
||||
uid: &NodeUid,
|
||||
old_parent_uid: &NodeUid,
|
||||
new_parent_ino: u64,
|
||||
new_parent_uid: &NodeUid,
|
||||
new_name: &str,
|
||||
authorized: bool,
|
||||
) -> Result<(), Errno> {
|
||||
if authorized {
|
||||
self.queue_rename_authorized(
|
||||
ino,
|
||||
uid,
|
||||
old_parent_uid,
|
||||
new_parent_ino,
|
||||
new_parent_uid,
|
||||
new_name,
|
||||
)
|
||||
} else {
|
||||
Core::queue_rename(
|
||||
self,
|
||||
ino,
|
||||
uid,
|
||||
old_parent_uid,
|
||||
new_parent_ino,
|
||||
new_parent_uid,
|
||||
new_name,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn rename_remote(
|
||||
&self,
|
||||
uid: &NodeUid,
|
||||
new_parent: Option<&NodeUid>,
|
||||
new_name: Option<&str>,
|
||||
) -> Result<bool, Errno> {
|
||||
let renamed = match (new_parent, new_name) {
|
||||
(Some(parent), name) => self.move_rename_remote(uid, parent, name),
|
||||
(None, Some(name)) => Core::rename_remote(self, uid, name),
|
||||
(None, None) => Ok(()),
|
||||
};
|
||||
match renamed {
|
||||
Ok(()) => Ok(true),
|
||||
Err(e) if self.lost_link(&e, "rename") => Ok(false),
|
||||
Err(e) => {
|
||||
error!(%uid, error = %e, "rename failed");
|
||||
Err(Errno::EIO)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn wake_drain(&self) {
|
||||
Core::wake_drain(self);
|
||||
}
|
||||
|
||||
fn trashed(&self, uid: &NodeUid, name: &str, open: bool) {
|
||||
if !open {
|
||||
self.evict_reader(uid);
|
||||
@@ -1960,20 +2023,6 @@ fn count_noun(n: usize, one: &str, many: &str) -> String {
|
||||
format!("{n} {}", if n == 1 { one } else { many })
|
||||
}
|
||||
|
||||
/// Whether a rename must be represented as a durable desired end state.
|
||||
/// Local-first, offline, or into a not-yet-uploaded directory, the API is not
|
||||
/// called in the syscall. Only remote-to-remote renames sent inline
|
||||
/// ([`Core::sends_inline`]) stay synchronous, so a successful kernel reply means
|
||||
/// the remote namespace has already reached the same end state.
|
||||
fn rename_needs_queue(
|
||||
inline: bool,
|
||||
destination_is_local: bool,
|
||||
_parent_changed: bool,
|
||||
_name_changed: bool,
|
||||
) -> bool {
|
||||
!inline || destination_is_local
|
||||
}
|
||||
|
||||
/// Bytes rendered with a binary unit and one decimal place (e.g. `"1.2 GB"`),
|
||||
/// for the activity log. Uses 1024-based steps but the shorter SI labels.
|
||||
fn human_bytes(bytes: u64) -> String {
|
||||
@@ -2098,9 +2147,9 @@ mod tests {
|
||||
copy_pending_for_truncate, fuse_name, is_stale_mount, node_visible, off_the_runtime,
|
||||
orphan_past_retention, prepare_shared_roots, preserve_on_access_denied,
|
||||
publish_virtual_root_in_listing, reconcile_virtual_root_in_listing,
|
||||
release_can_discard_unlinked, release_must_retain_queued_trash, rename_needs_queue,
|
||||
require_node_parent_access, require_rename_access, resolve_anywhere_with,
|
||||
shared_with_me_uid, uid_write_authority, virtual_node,
|
||||
release_can_discard_unlinked, release_must_retain_queued_trash, require_node_parent_access,
|
||||
require_rename_access, resolve_anywhere_with, shared_with_me_uid, uid_write_authority,
|
||||
virtual_node,
|
||||
};
|
||||
use super::{Db, WriteAuthority};
|
||||
use std::time::Duration;
|
||||
@@ -3084,20 +3133,6 @@ mod tests {
|
||||
assert_ne!(pending.meta.authored, vec![(0, pending.meta.len)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn online_combined_cross_directory_rename_stays_synchronous() {
|
||||
assert!(!rename_needs_queue(true, false, true, true));
|
||||
assert!(rename_needs_queue(false, false, false, true));
|
||||
assert!(rename_needs_queue(true, true, true, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_step_online_namespace_changes_stay_synchronous() {
|
||||
assert!(!rename_needs_queue(true, false, false, true));
|
||||
assert!(!rename_needs_queue(true, false, true, false));
|
||||
assert!(!rename_needs_queue(true, false, false, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fuse_names_enforce_linux_component_limits() {
|
||||
use std::ffi::OsStr;
|
||||
@@ -3443,11 +3478,13 @@ mod tests {
|
||||
assert_before(function, gate, remote_call);
|
||||
}
|
||||
|
||||
let filesystem = include_str!("filesystem.rs");
|
||||
let rename = function_source(filesystem, "fn serve_rename(");
|
||||
assert_before(rename, "require_rename_access", "remove_replaced");
|
||||
assert_before(rename, "remove_replaced", "queue_rename_authorized");
|
||||
assert_before(rename, "require_rename_access", "rename_remote");
|
||||
let rename = function_source(namespace, "pub fn rename(");
|
||||
assert_before(rename, "self.authorize_replace(", "remove_replaced");
|
||||
assert_before(rename, "remove_replaced", "self.host.queue_rename(");
|
||||
assert_before(rename, "self.require_rename_access(", ".rename_remote(");
|
||||
let authorize = function_source(namespace, "fn authorize_replace(");
|
||||
assert_before(authorize, "check_replaceable", "require_rename_access");
|
||||
assert_before(authorize, "require_rename_access", "ReplaceJournal::begin");
|
||||
let control_mkdir = function_source(source, "fn create_folder(");
|
||||
assert_before(
|
||||
control_mkdir,
|
||||
@@ -3834,10 +3871,13 @@ mod tests {
|
||||
// Through the raw lock, the move stayed in the state's outbox, and the
|
||||
// next lookup rebuilt the destination from a database without it
|
||||
// (B135).
|
||||
let rename: String = function_source(include_str!("filesystem.rs"), "fn serve_rename(")
|
||||
.split_whitespace()
|
||||
.collect();
|
||||
assert!(rename.contains("self.core.state().relocate("));
|
||||
let rename: String = function_source(
|
||||
include_str!("../../pdfs-vfs/src/namespace.rs"),
|
||||
"pub fn rename(",
|
||||
)
|
||||
.split_whitespace()
|
||||
.collect();
|
||||
assert!(rename.contains("self.state().relocate("));
|
||||
assert!(!rename.contains(".lock().relocate("));
|
||||
}
|
||||
|
||||
|
||||
@@ -2875,6 +2875,67 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn a_listing_taken_while_a_withdrawn_create_lands_does_not_keep_it() {
|
||||
// A file deleted while its create was on the wire. Drive made the node
|
||||
// and listed it before the drain had its answer, and a refresh then put
|
||||
// it in the tree. The drain hid it and trashed it, but the entry stayed:
|
||||
// a new file made under the name opened the trashed node, and every
|
||||
// write and rename of it was refused with EACCES (B303).
|
||||
let drive = FakeDrive::new();
|
||||
let dir = scratch("withdrawn-create-listed");
|
||||
let daemon = Daemon::start(&dir, drive.client(1, Faults::lan())).unwrap();
|
||||
let mnt = daemon.mountpoint.clone();
|
||||
let file = |bytes: &[u8]| Some(Entry::File(Arc::new(bytes.to_vec())));
|
||||
|
||||
let held = daemon.client.hold_reply_to_next_create();
|
||||
daemon.write_new(&mnt.join("d"), b"first").unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || held.reached()));
|
||||
std::fs::remove_file(mnt.join("d")).unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || {
|
||||
drive.tree().get("d").cloned() == file(b"first")
|
||||
}));
|
||||
// Past the listing lag, so the refresh finds the node Drive made.
|
||||
std::thread::sleep(Duration::from_millis(300));
|
||||
let refresh = Request::Refresh {
|
||||
scope: RefreshScope::Dir {
|
||||
path: mnt.to_string_lossy().into_owned(),
|
||||
},
|
||||
};
|
||||
assert!(matches!(daemon.request(&refresh), Ok(Response::Ok { .. })));
|
||||
let _ = std::fs::read_dir(&mnt).unwrap().count();
|
||||
drop(held);
|
||||
assert!(
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
daemon.pending().is_ok_and(|items| items.is_empty())
|
||||
&& !drive.tree().contains_key("d")
|
||||
}),
|
||||
"{:?} {:?}",
|
||||
daemon.pending(),
|
||||
drive.tree()
|
||||
);
|
||||
assert!(
|
||||
!mnt.join("d").exists(),
|
||||
"the trashed create is still listed"
|
||||
);
|
||||
|
||||
std::fs::write(mnt.join("d"), b"second").unwrap();
|
||||
std::fs::rename(mnt.join("d"), mnt.join("c.bin")).unwrap();
|
||||
assert!(
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
daemon.pending().is_ok_and(|items| items.is_empty())
|
||||
&& drive.tree().get("c.bin").cloned() == file(b"second")
|
||||
}),
|
||||
"{:?} {:?}",
|
||||
daemon.pending(),
|
||||
drive.tree()
|
||||
);
|
||||
|
||||
assert!(matches!(daemon.stop(), Ok(MountOutcome::Shutdown)));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn a_file_made_under_the_name_of_a_create_on_the_wire_waits_for_it() {
|
||||
@@ -4567,6 +4628,8 @@ mod tests {
|
||||
fn a_replace_cut_off_after_its_trash_brings_the_replaced_file_back() {
|
||||
let drive = FakeDrive::new();
|
||||
let dir = scratch("replace-cut-trash");
|
||||
// Only this test's daemons in the log a failure prints.
|
||||
take_logged();
|
||||
let daemon = Daemon::start(&dir, drive.client(1, Faults::lan())).unwrap();
|
||||
std::fs::write(daemon.mountpoint.join("report.odt"), b"old").unwrap();
|
||||
std::fs::write(daemon.mountpoint.join("report.odt.tmp"), b"new").unwrap();
|
||||
@@ -4590,8 +4653,9 @@ mod tests {
|
||||
wait_until(Duration::from_secs(30), || {
|
||||
drive.tree().get("report.odt") == Some(&Entry::File(Arc::new(b"old".to_vec())))
|
||||
}),
|
||||
"the replaced file came back: {:?}",
|
||||
drive.tree()
|
||||
"the replaced file came back: {:?}\n{}",
|
||||
drive.tree(),
|
||||
take_logged().join("\n")
|
||||
);
|
||||
assert!(drive.tree().contains_key("report.odt.tmp"));
|
||||
assert!(wait_until(Duration::from_secs(30), || {
|
||||
|
||||
@@ -438,25 +438,6 @@ fn is_in_memory(path: &Path) -> bool {
|
||||
p == ":memory:" || p.is_empty()
|
||||
}
|
||||
|
||||
/// Take the single-instance write lock for the database at `path`.
|
||||
///
|
||||
/// The daemon is the only writer by design — the front-ends go through the
|
||||
/// control socket — but nothing stopped a hand-run `pdfs mount` from starting
|
||||
/// alongside the systemd unit, at which point two processes own the same inode
|
||||
/// space, the same content cache, and the same drain queue. SQLite's own
|
||||
/// locking makes each *statement* safe and does nothing about that.
|
||||
///
|
||||
/// `flock` on a sibling `.lock` file rather than on the database itself:
|
||||
/// SQLite uses POSIX record locks, so the two never interact, and a lock file
|
||||
/// left behind carries no state — the lock lives in the kernel and dies with
|
||||
/// the process, however it exits.
|
||||
///
|
||||
/// A refusal is retried for [`LOCK_RETRY`] before it counts as another
|
||||
/// daemon. A child this process spawns holds a copy of every descriptor from
|
||||
/// its fork until its exec closes them, and `flock` belongs to the open file,
|
||||
/// not the descriptor. So a lock the process has just let go of can stay held
|
||||
/// for that moment, and a reopen right after a drop is refused
|
||||
/// (`docs/BUGS.md` B290).
|
||||
/// A value no other opening of a database has used: the time in nanoseconds,
|
||||
/// made unique within this process by a counter.
|
||||
fn next_run() -> u64 {
|
||||
@@ -476,6 +457,25 @@ fn next_run() -> u64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Take the single-instance write lock for the database at `path`.
|
||||
///
|
||||
/// The daemon is the only writer by design — the front-ends go through the
|
||||
/// control socket — but nothing stopped a hand-run `pdfs mount` from starting
|
||||
/// alongside the systemd unit, at which point two processes own the same inode
|
||||
/// space, the same content cache, and the same drain queue. SQLite's own
|
||||
/// locking makes each *statement* safe and does nothing about that.
|
||||
///
|
||||
/// `flock` on a sibling `.lock` file rather than on the database itself:
|
||||
/// SQLite uses POSIX record locks, so the two never interact, and a lock file
|
||||
/// left behind carries no state — the lock lives in the kernel and dies with
|
||||
/// the process, however it exits.
|
||||
///
|
||||
/// A refusal is retried for [`LOCK_RETRY`] before it counts as another
|
||||
/// daemon. A child this process spawns holds a copy of every descriptor from
|
||||
/// its fork until its exec closes them, and `flock` belongs to the open file,
|
||||
/// not the descriptor. So a lock the process has just let go of can stay held
|
||||
/// for that moment, and a reopen right after a drop is refused
|
||||
/// (`docs/BUGS.md` B290).
|
||||
fn acquire_single_writer_lock(path: &Path) -> Result<Option<File>> {
|
||||
if is_in_memory(path) {
|
||||
return Ok(None);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
//! ([`writes`]); the POSIX rules on names and on what a rename may replace
|
||||
//! ([`names`]); which nodes a folder lists ([`nodes`]); and two services
|
||||
//! behind host ports: the open files from open to close ([`files`]), and
|
||||
//! create, mkdir, unlink and rmdir ([`namespace`]).
|
||||
//! create, mkdir, unlink, rmdir and rename ([`namespace`]).
|
||||
|
||||
pub mod files;
|
||||
pub mod ids;
|
||||
|
||||
@@ -16,12 +16,13 @@ use pdfs_core::Access;
|
||||
use pdfs_core::lockrank::Ranked;
|
||||
use pdfs_core::syncignore::is_transient_name;
|
||||
use pdfs_store::cache::ContentCache;
|
||||
use pdfs_store::db::Db;
|
||||
use pdfs_store::db::{Db, ReplaceIntent};
|
||||
use proton_drive_rs::Node;
|
||||
use proton_drive_rs::proton_sdk::ids::NodeUid;
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
use crate::ids::is_local_uid;
|
||||
use crate::names::{ReplaceError, check_replaceable};
|
||||
use crate::open::WriteHandle;
|
||||
use crate::tree::{State, StateGuard};
|
||||
use crate::writes::WriteState;
|
||||
@@ -100,16 +101,25 @@ pub fn settle_from_drive(
|
||||
/// unchanged.
|
||||
#[derive(Debug)]
|
||||
pub enum NamespaceError<E> {
|
||||
/// The parent folder is not in the tree.
|
||||
/// The node or its folder is not in the tree.
|
||||
NotFound,
|
||||
/// `unlink` named a folder.
|
||||
/// `unlink` named a folder, or a rename would put a file over one.
|
||||
IsDirectory,
|
||||
/// `rmdir` named a file.
|
||||
/// `rmdir` named a file, or a rename would put a folder over one.
|
||||
NotDirectory,
|
||||
/// `rmdir` named a folder that still has children.
|
||||
/// `rmdir` named a folder that still has children, or a rename would
|
||||
/// replace one.
|
||||
NotEmpty,
|
||||
/// A rename that cannot be done: a folder into its own subtree, or an
|
||||
/// exchange of two names.
|
||||
InvalidArgument,
|
||||
/// A rename that may not replace found its destination taken.
|
||||
Exists,
|
||||
/// The queued create of a node went away under its rename: try again.
|
||||
Busy,
|
||||
/// Something failed that the service already logged: the scratch file of
|
||||
/// a new file.
|
||||
/// a new file, the journal of a replacing rename, or the queued create a
|
||||
/// rename rewrites.
|
||||
Io,
|
||||
/// The host failed, with its own error.
|
||||
Host(E),
|
||||
@@ -136,8 +146,9 @@ pub trait NamespaceHost {
|
||||
/// Make sure the tree holds the children of folder `ino`.
|
||||
fn ensure_children(&self, ino: u64) -> Result<(), Self::Error>;
|
||||
|
||||
/// The child `name` of folder `parent`, as its inode and uid.
|
||||
fn lookup_child(&self, parent: u64, name: &str) -> Result<(u64, NodeUid), Self::Error>;
|
||||
/// The child `name` of folder `parent`, as its inode and uid, or `None`
|
||||
/// when the folder has no such child.
|
||||
fn lookup_child(&self, parent: u64, name: &str) -> Result<Option<(u64, NodeUid)>, Self::Error>;
|
||||
|
||||
/// Whether a change goes to Drive now rather than into the queue.
|
||||
fn sends_inline(&self) -> bool;
|
||||
@@ -188,6 +199,42 @@ pub trait NamespaceHost {
|
||||
/// instead, as the link went down on the way. The host logs a failure.
|
||||
fn trash_remote(&self, uid: &NodeUid, name: &str) -> Result<bool, Self::Error>;
|
||||
|
||||
/// Remove the node `uid` that a rename to `name` replaces: trash it on
|
||||
/// Drive or queue its trash.
|
||||
fn remove_replaced(&self, ino: u64, uid: &NodeUid, name: &str) -> Result<(), Self::Error>;
|
||||
|
||||
/// Put back the node a failed rename to `name` under `parent` removed.
|
||||
fn restore_replaced(&self, victim: Option<&(u64, NodeUid)>, parent: &NodeUid, name: &str);
|
||||
|
||||
/// Queue the rename of `uid` to `new_name` under `new_parent_uid`.
|
||||
/// `authorized` says the access to replace a destination was already
|
||||
/// checked.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn queue_rename(
|
||||
&self,
|
||||
ino: u64,
|
||||
uid: &NodeUid,
|
||||
old_parent_uid: &NodeUid,
|
||||
new_parent_ino: u64,
|
||||
new_parent_uid: &NodeUid,
|
||||
new_name: &str,
|
||||
authorized: bool,
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Move `uid` to `new_parent` and rename it to `new_name` on Drive, in
|
||||
/// one request; `None` leaves that part as it is. `Ok(false)` asks for
|
||||
/// the rename to be queued instead, as the link went down on the way. The
|
||||
/// host logs a failure.
|
||||
fn rename_remote(
|
||||
&self,
|
||||
uid: &NodeUid,
|
||||
new_parent: Option<&NodeUid>,
|
||||
new_name: Option<&str>,
|
||||
) -> Result<bool, Self::Error>;
|
||||
|
||||
/// Let the drain look at the queue again.
|
||||
fn wake_drain(&self);
|
||||
|
||||
/// Drive accepted the trash of `uid`, and its queued operations and
|
||||
/// cached bytes are gone: forget what else the host keeps of it and record
|
||||
/// the trash. `open` means a handle still has it open, and reads of it
|
||||
@@ -205,8 +252,79 @@ pub struct Made {
|
||||
pub access: Access,
|
||||
}
|
||||
|
||||
/// How a rename treats an existing destination.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub struct RenameFlags {
|
||||
/// Fail with [`NamespaceError::Exists`] instead of replacing it.
|
||||
pub no_replace: bool,
|
||||
/// Swap the two names, which Drive cannot do.
|
||||
pub exchange: bool,
|
||||
}
|
||||
|
||||
/// How a rename ended.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Renamed {
|
||||
/// Drive has the new name, or nothing on Drive had to change.
|
||||
Done,
|
||||
/// The rename is queued. The kernel's cached entries for both names are
|
||||
/// stale: drop them after the answer, since the kernel updates its cache
|
||||
/// while it processes the answer and would overwrite an earlier
|
||||
/// invalidation.
|
||||
Queued,
|
||||
}
|
||||
|
||||
/// Whether a rename is queued rather than sent now. Local-first, offline, or
|
||||
/// into a folder not created on Drive yet, the API is not called in the
|
||||
/// syscall. Only renames between nodes Drive has, sent inline, stay
|
||||
/// synchronous, so a successful answer means Drive already has the end state.
|
||||
pub fn rename_needs_queue(inline: bool, destination_is_local: bool) -> bool {
|
||||
!inline || destination_is_local
|
||||
}
|
||||
|
||||
/// A replacing rename's journal entry, ended when the rename returns, however
|
||||
/// it returns. Only a stop leaves it behind, and that is what it is for.
|
||||
struct ReplaceJournal {
|
||||
db: Arc<Db>,
|
||||
source: String,
|
||||
}
|
||||
|
||||
impl ReplaceJournal {
|
||||
fn begin(
|
||||
db: &Arc<Db>,
|
||||
source: &NodeUid,
|
||||
victim: &NodeUid,
|
||||
new_parent: &NodeUid,
|
||||
new_name: &str,
|
||||
) -> pdfs_core::Result<Self> {
|
||||
let source = source.to_string();
|
||||
let started_ms = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map_or(0, |d| d.as_millis() as i64);
|
||||
db.begin_replace(&ReplaceIntent {
|
||||
source_uid: source.clone(),
|
||||
victim_uid: victim.to_string(),
|
||||
new_parent_uid: new_parent.to_string(),
|
||||
new_name: new_name.to_owned(),
|
||||
started_ms,
|
||||
run: 0,
|
||||
})?;
|
||||
Ok(Self {
|
||||
db: db.clone(),
|
||||
source,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ReplaceJournal {
|
||||
fn drop(&mut self) {
|
||||
if let Err(error) = self.db.end_replace(&self.source) {
|
||||
warn!(source = %self.source, %error, "ending a replacing rename's journal entry failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The namespace service of one daemon, shared by every mount: create,
|
||||
/// mkdir, unlink and rmdir.
|
||||
/// mkdir, unlink, rmdir and rename.
|
||||
pub struct Namespace<H> {
|
||||
state: Arc<Ranked<State>>,
|
||||
db: Arc<Db>,
|
||||
@@ -352,7 +470,7 @@ impl<H: NamespaceHost> Namespace<H> {
|
||||
/// Remove the file `name` from folder `parent`.
|
||||
pub fn unlink(&self, parent: u64, name: &str) -> Result<(), NamespaceError<H::Error>> {
|
||||
self.host.require_writable(parent)?;
|
||||
if let Ok((ino, _)) = self.host.lookup_child(parent, name)
|
||||
if let Ok(Some((ino, _))) = self.host.lookup_child(parent, name)
|
||||
&& self
|
||||
.state
|
||||
.lock()
|
||||
@@ -368,7 +486,7 @@ impl<H: NamespaceHost> Namespace<H> {
|
||||
/// Remove the empty folder `name` from folder `parent`.
|
||||
pub fn rmdir(&self, parent: u64, name: &str) -> Result<(), NamespaceError<H::Error>> {
|
||||
self.host.require_writable(parent)?;
|
||||
if let Ok((ino, _)) = self.host.lookup_child(parent, name) {
|
||||
if let Ok(Some((ino, _))) = self.host.lookup_child(parent, name) {
|
||||
if self
|
||||
.state
|
||||
.lock()
|
||||
@@ -389,11 +507,265 @@ impl<H: NamespaceHost> Namespace<H> {
|
||||
self.trash_child(parent, name)
|
||||
}
|
||||
|
||||
/// Rename the child `name` of folder `parent` to `newname` in folder
|
||||
/// `newparent`.
|
||||
///
|
||||
/// `rename(2)` replaces an existing destination. Drive has no replacing
|
||||
/// rename, so the victim is removed first and the operation stops being
|
||||
/// atomic. Without that, Drive's refusal surfaced as an error and every
|
||||
/// write-to-temp-then-rename tool (rsync, atomic editor saves) failed at
|
||||
/// the very end of its transfer (`docs/BUGS.md` B13). A journal entry
|
||||
/// written before the victim is removed, and ended when this returns,
|
||||
/// lets a stop in between be settled on the next start (B302).
|
||||
pub fn rename(
|
||||
&self,
|
||||
parent: u64,
|
||||
name: &str,
|
||||
newparent: u64,
|
||||
newname: &str,
|
||||
flags: RenameFlags,
|
||||
) -> Result<Renamed, NamespaceError<H::Error>> {
|
||||
self.host.require_writable(parent)?;
|
||||
self.host.require_writable(newparent)?;
|
||||
let (ino, mut uid) = self
|
||||
.host
|
||||
.lookup_child(parent, name)?
|
||||
.ok_or(NamespaceError::NotFound)?;
|
||||
// Moving a folder into itself or one of its descendants is forbidden
|
||||
// by POSIX.
|
||||
{
|
||||
let st = self.state.lock();
|
||||
if st.entries.get(&ino).is_some_and(|e| e.node.is_folder())
|
||||
&& st.is_ancestor_of(ino, newparent)
|
||||
{
|
||||
return Err(NamespaceError::InvalidArgument);
|
||||
}
|
||||
}
|
||||
// The destination has to be listed either way: the queued path pushes
|
||||
// the node into that listing, and the online one drops it to force a
|
||||
// re-enumeration.
|
||||
if newparent != parent {
|
||||
self.host.ensure_children(newparent)?;
|
||||
}
|
||||
let (old_parent_uid, new_parent_uid) = {
|
||||
let st = self.state.lock();
|
||||
match (st.entries.get(&parent), st.entries.get(&newparent)) {
|
||||
(Some(old), Some(new)) => (old.uid.clone(), new.uid.clone()),
|
||||
_ => return Err(NamespaceError::NotFound),
|
||||
}
|
||||
};
|
||||
// `RENAME_EXCHANGE` has no Drive primitive and cannot be emulated
|
||||
// without a window in which one of the two names does not exist.
|
||||
if flags.exchange {
|
||||
return Err(NamespaceError::InvalidArgument);
|
||||
}
|
||||
let victim = match self.host.lookup_child(newparent, newname)? {
|
||||
// Renaming a node onto its own name is a no-op, never a
|
||||
// self-replace.
|
||||
Some((_, victim_uid)) if victim_uid == uid => None,
|
||||
found => found,
|
||||
};
|
||||
let _journal = match &victim {
|
||||
Some((victim_ino, victim_uid)) => {
|
||||
if flags.no_replace {
|
||||
return Err(NamespaceError::Exists);
|
||||
}
|
||||
let journal = self.authorize_replace(
|
||||
ino,
|
||||
&uid,
|
||||
*victim_ino,
|
||||
victim_uid,
|
||||
&old_parent_uid,
|
||||
&new_parent_uid,
|
||||
newname,
|
||||
)?;
|
||||
self.host
|
||||
.remove_replaced(*victim_ino, victim_uid, newname)?;
|
||||
Some(journal)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let replacing = victim.is_some();
|
||||
let restore = || {
|
||||
self.host
|
||||
.restore_replaced(victim.as_ref(), &new_parent_uid, newname)
|
||||
};
|
||||
// A node whose own creation is still queued has no identity on Drive
|
||||
// to rename: the queued operation is the node, so rewriting its target
|
||||
// is the whole rename. Nothing reaches the API, which is why this
|
||||
// works offline. A create that lands meanwhile leaves no operation to
|
||||
// rewrite; the node is then renamed by the uid Drive gave it
|
||||
// (`docs/BUGS.md` B142).
|
||||
if is_local_uid(&uid) {
|
||||
match self
|
||||
.db
|
||||
.rewrite_op_target(&uid.to_string(), &new_parent_uid.to_string(), newname)
|
||||
{
|
||||
Ok(true) => {
|
||||
self.state()
|
||||
.rename_in_place(ino, newparent, &new_parent_uid, newname);
|
||||
// A create that failed on its old name is due again.
|
||||
self.host.wake_drain();
|
||||
// A transient scratch file (its create parked, bytes held
|
||||
// back) renamed to a finished name is the moment the file
|
||||
// is meant to reach Drive: un-park the create so the drain
|
||||
// uploads it once (`docs/BUGS.md` B70). Renaming to another
|
||||
// transient name leaves it parked.
|
||||
if is_transient_name(name) && !is_transient_name(newname) {
|
||||
match self.db.set_create_hold(&uid.to_string(), false) {
|
||||
Ok(_) => {
|
||||
self.host.wake_drain();
|
||||
debug!(%uid, newname, "un-parked a finalized transient create");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(%uid, error = %e, "un-parking a finalized transient create failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
debug!(%uid, newname, "renamed a node whose create is still queued");
|
||||
return Ok(Renamed::Done);
|
||||
}
|
||||
Ok(false) => match self.host.landed_uid(ino) {
|
||||
Some(real) => {
|
||||
debug!(local = %uid, %real, newname, "create landed under a rename");
|
||||
uid = real;
|
||||
}
|
||||
None => {
|
||||
warn!(%uid, name, newname, "queued create vanished under a rename");
|
||||
restore();
|
||||
return Err(NamespaceError::Busy);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
error!(%uid, error = %e, "rewriting a queued create's target failed");
|
||||
restore();
|
||||
return Err(NamespaceError::Io);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Offline, or into a folder that does not exist on Drive yet, the
|
||||
// rename is queued. The network going away under the inline path
|
||||
// lands there too, with whatever half already reached Drive: the
|
||||
// queued operation records the end state, so the drain finishes the
|
||||
// rest.
|
||||
let queue = || match self.host.queue_rename(
|
||||
ino,
|
||||
&uid,
|
||||
&old_parent_uid,
|
||||
newparent,
|
||||
&new_parent_uid,
|
||||
newname,
|
||||
replacing,
|
||||
) {
|
||||
Ok(()) => Ok(Renamed::Queued),
|
||||
Err(error) => {
|
||||
restore();
|
||||
Err(NamespaceError::Host(error))
|
||||
}
|
||||
};
|
||||
if rename_needs_queue(self.host.sends_inline(), is_local_uid(&new_parent_uid)) {
|
||||
return queue();
|
||||
}
|
||||
// A failure past this point has already trashed any node the rename
|
||||
// was replacing, so put it back rather than leaving the caller with
|
||||
// neither the source moved nor the destination intact.
|
||||
if let Err(error) = self.require_rename_access(&uid, &old_parent_uid, &new_parent_uid) {
|
||||
restore();
|
||||
return Err(error);
|
||||
}
|
||||
// A move that also renames is one request, so the name only has to be
|
||||
// free in the destination, and the answer never stands for half of
|
||||
// it.
|
||||
let to_parent = (newparent != parent).then_some(&new_parent_uid);
|
||||
let to_name = (newname != name).then_some(newname);
|
||||
match self.host.rename_remote(&uid, to_parent, to_name) {
|
||||
Ok(true) => {}
|
||||
Ok(false) => return queue(),
|
||||
Err(error) => {
|
||||
restore();
|
||||
return Err(NamespaceError::Host(error));
|
||||
}
|
||||
}
|
||||
// Through the guard, so the database has both folders unlisted before
|
||||
// the answer. The next lookup rebuilds a folder still marked listed
|
||||
// from the database, which did not have the move yet
|
||||
// (`docs/BUGS.md` B135).
|
||||
self.state()
|
||||
.relocate(ino, parent, newparent, &new_parent_uid, newname);
|
||||
Ok(Renamed::Done)
|
||||
}
|
||||
|
||||
/// Check that `uid` may replace the victim, and record the replace in the
|
||||
/// journal. Nothing is removed yet.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn authorize_replace(
|
||||
&self,
|
||||
ino: u64,
|
||||
uid: &NodeUid,
|
||||
victim_ino: u64,
|
||||
victim_uid: &NodeUid,
|
||||
old_parent_uid: &NodeUid,
|
||||
new_parent_uid: &NodeUid,
|
||||
newname: &str,
|
||||
) -> Result<ReplaceJournal, NamespaceError<H::Error>> {
|
||||
// POSIX requires both ends to agree on being a directory, and the
|
||||
// check has to happen before anything is trashed: getting it wrong
|
||||
// turns a refusal into the destruction of the destination.
|
||||
let (src_dir, dst_dir) = {
|
||||
let st = self.state.lock();
|
||||
let is_dir = |i: u64| st.entries.get(&i).map(|e| e.node.is_folder());
|
||||
match (is_dir(ino), is_dir(victim_ino)) {
|
||||
(Some(a), Some(b)) => (a, b),
|
||||
_ => return Err(NamespaceError::NotFound),
|
||||
}
|
||||
};
|
||||
// Replacing a folder means trashing it, and Drive trashes a folder
|
||||
// with its whole subtree, so the destination's emptiness has to be
|
||||
// known before the decision is made.
|
||||
let dst_empty = if dst_dir {
|
||||
self.host.ensure_children(victim_ino)?;
|
||||
self.state
|
||||
.lock()
|
||||
.children
|
||||
.get(&victim_ino)
|
||||
.is_none_or(|kids| kids.is_empty())
|
||||
} else {
|
||||
true
|
||||
};
|
||||
check_replaceable(src_dir, dst_dir, dst_empty).map_err(|error| match error {
|
||||
ReplaceError::IsDirectory => NamespaceError::IsDirectory,
|
||||
ReplaceError::NotDirectory => NamespaceError::NotDirectory,
|
||||
ReplaceError::NotEmpty => NamespaceError::NotEmpty,
|
||||
})?;
|
||||
self.require_rename_access(uid, old_parent_uid, new_parent_uid)?;
|
||||
ReplaceJournal::begin(&self.db, uid, victim_uid, new_parent_uid, newname).map_err(|error| {
|
||||
error!(%uid, %error, "recording a replacing rename failed; refusing it");
|
||||
NamespaceError::Io
|
||||
})
|
||||
}
|
||||
|
||||
/// A rename changes the node and both of its folders on Drive, so all
|
||||
/// three have to allow it.
|
||||
fn require_rename_access(
|
||||
&self,
|
||||
uid: &NodeUid,
|
||||
old_parent_uid: &NodeUid,
|
||||
new_parent_uid: &NodeUid,
|
||||
) -> Result<(), NamespaceError<H::Error>> {
|
||||
for authority in [uid, old_parent_uid, new_parent_uid] {
|
||||
self.host.require_uid_writable(authority)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Trash the child `name` of folder `parent`, on Drive or through the
|
||||
/// queue.
|
||||
fn trash_child(&self, parent: u64, name: &str) -> Result<(), NamespaceError<H::Error>> {
|
||||
self.host.require_writable(parent)?;
|
||||
let (ino, mut uid) = self.host.lookup_child(parent, name)?;
|
||||
let (ino, mut uid) = self
|
||||
.host
|
||||
.lookup_child(parent, name)?
|
||||
.ok_or(NamespaceError::NotFound)?;
|
||||
let open_now = self
|
||||
.state
|
||||
.lock()
|
||||
@@ -600,8 +972,11 @@ mod service_tests {
|
||||
/// changes go to Drive now; `link_up` whether Drive answers when asked.
|
||||
struct Recorder {
|
||||
state: Arc<Ranked<State>>,
|
||||
db: Arc<Db>,
|
||||
inline: bool,
|
||||
link_up: bool,
|
||||
/// Drive refuses a rename outright.
|
||||
refuse_rename: bool,
|
||||
calls: Mutex<Vec<String>>,
|
||||
}
|
||||
|
||||
@@ -626,16 +1001,20 @@ mod service_tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn lookup_child(&self, parent: u64, name: &str) -> Result<(u64, NodeUid), &'static str> {
|
||||
fn lookup_child(
|
||||
&self,
|
||||
parent: u64,
|
||||
name: &str,
|
||||
) -> Result<Option<(u64, NodeUid)>, &'static str> {
|
||||
let st = self.state.lock();
|
||||
st.children
|
||||
Ok(st
|
||||
.children
|
||||
.get(&parent)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|ino| st.entries.get(ino).map(|entry| (*ino, entry)))
|
||||
.find(|(_, entry)| entry.node.name == name)
|
||||
.map(|(ino, entry)| (ino, entry.uid.clone()))
|
||||
.ok_or("no such child")
|
||||
.map(|(ino, entry)| (ino, entry.uid.clone())))
|
||||
}
|
||||
|
||||
fn sends_inline(&self) -> bool {
|
||||
@@ -703,6 +1082,71 @@ mod service_tests {
|
||||
fn trashed(&self, uid: &NodeUid, _name: &str, open: bool) {
|
||||
self.record(format!("trashed {uid} open={open}"));
|
||||
}
|
||||
|
||||
fn remove_replaced(
|
||||
&self,
|
||||
ino: u64,
|
||||
uid: &NodeUid,
|
||||
_name: &str,
|
||||
) -> Result<(), &'static str> {
|
||||
// The tests replace with the node "a": its journal entry has to be
|
||||
// on disk before anything is removed.
|
||||
let journaled = self
|
||||
.db
|
||||
.state_str(&format!("replace:{}", self::uid("a")))
|
||||
.unwrap()
|
||||
.is_some();
|
||||
self.record(format!("remove replaced {uid} journaled={journaled}"));
|
||||
let _ = ino;
|
||||
StateGuard::new(self.state.lock(), &self.db).forget_or_unlink(uid);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn restore_replaced(
|
||||
&self,
|
||||
victim: Option<&(u64, NodeUid)>,
|
||||
_parent: &NodeUid,
|
||||
_name: &str,
|
||||
) {
|
||||
if let Some((_, uid)) = victim {
|
||||
self.record(format!("restore {uid}"));
|
||||
}
|
||||
}
|
||||
|
||||
fn queue_rename(
|
||||
&self,
|
||||
_ino: u64,
|
||||
uid: &NodeUid,
|
||||
_old_parent_uid: &NodeUid,
|
||||
_new_parent_ino: u64,
|
||||
_new_parent_uid: &NodeUid,
|
||||
new_name: &str,
|
||||
authorized: bool,
|
||||
) -> Result<(), &'static str> {
|
||||
self.record(format!(
|
||||
"queue rename {uid} to {new_name} authorized={authorized}"
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rename_remote(
|
||||
&self,
|
||||
uid: &NodeUid,
|
||||
new_parent: Option<&NodeUid>,
|
||||
new_name: Option<&str>,
|
||||
) -> Result<bool, &'static str> {
|
||||
self.record(format!(
|
||||
"rename {uid} parent={} name={}",
|
||||
new_parent.map_or("-".to_owned(), |p| p.to_string()),
|
||||
new_name.unwrap_or("-")
|
||||
));
|
||||
if self.refuse_rename {
|
||||
return Err("refused");
|
||||
}
|
||||
Ok(self.link_up)
|
||||
}
|
||||
|
||||
fn wake_drain(&self) {}
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
@@ -717,6 +1161,10 @@ mod service_tests {
|
||||
|
||||
impl Fixture {
|
||||
fn new(inline: bool, link_up: bool) -> Self {
|
||||
Self::with(inline, link_up, false)
|
||||
}
|
||||
|
||||
fn with(inline: bool, link_up: bool, refuse_rename: bool) -> Self {
|
||||
let tmp = TempDir::new();
|
||||
let db = Arc::new(Db::open(&tmp.0.join("cache.db")).unwrap());
|
||||
let cache = Arc::new(
|
||||
@@ -729,8 +1177,10 @@ mod service_tests {
|
||||
));
|
||||
let host: &'static Recorder = Box::leak(Box::new(Recorder {
|
||||
state: state.clone(),
|
||||
db: db.clone(),
|
||||
inline,
|
||||
link_up,
|
||||
refuse_rename,
|
||||
calls: Mutex::default(),
|
||||
}));
|
||||
let dir = {
|
||||
@@ -763,7 +1213,24 @@ mod service_tests {
|
||||
}
|
||||
|
||||
fn listed(&self, name: &str) -> bool {
|
||||
self.host.lookup_child(self.dir, name).is_ok()
|
||||
self.child(self.dir, name).is_some()
|
||||
}
|
||||
|
||||
fn child(&self, parent: u64, name: &str) -> Option<(u64, NodeUid)> {
|
||||
self.host.lookup_child(parent, name).unwrap()
|
||||
}
|
||||
|
||||
/// Put a node Drive has into folder `parent`, and return its inode.
|
||||
fn put(&self, parent: u64, link: &str, folder: bool) -> u64 {
|
||||
let parent_uid = self.state.lock().entries[&parent].uid.clone();
|
||||
let node = local_node(uid(link), parent_uid, link.to_owned(), folder);
|
||||
let mut st = self.state();
|
||||
let ino = st.intern(parent, node);
|
||||
st.children.get_mut(&parent).unwrap().push(ino);
|
||||
if folder {
|
||||
st.children.insert(ino, Vec::new());
|
||||
}
|
||||
ino
|
||||
}
|
||||
|
||||
fn state(&self) -> StateGuard<'_> {
|
||||
@@ -820,7 +1287,7 @@ mod service_tests {
|
||||
let fx = Fixture::new(true, true);
|
||||
fx.namespace.mkdir(fx.dir, "sub").unwrap();
|
||||
fx.namespace.create(fx.dir, "a.txt").unwrap();
|
||||
let sub = fx.host.lookup_child(fx.dir, "sub").unwrap().0;
|
||||
let sub = fx.child(fx.dir, "sub").unwrap().0;
|
||||
fx.namespace.create(sub, "inner.txt").unwrap();
|
||||
fx.calls();
|
||||
|
||||
@@ -893,4 +1360,179 @@ mod service_tests {
|
||||
assert_eq!(fx.calls(), [format!("drop queued {uid} keep_staged=false")]);
|
||||
assert!(!fx.listed("a.txt"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_online_move_is_one_request_and_moves_the_entry() {
|
||||
let fx = Fixture::new(true, true);
|
||||
let sub = fx.put(fx.dir, "sub", true);
|
||||
let a = fx.put(fx.dir, "a", false);
|
||||
let renamed = fx
|
||||
.namespace
|
||||
.rename(fx.dir, "a", sub, "b", RenameFlags::default())
|
||||
.unwrap();
|
||||
assert_eq!(renamed, Renamed::Done);
|
||||
assert_eq!(
|
||||
fx.calls(),
|
||||
[format!("rename {} parent={} name=b", uid("a"), uid("sub"))]
|
||||
);
|
||||
// Both folders are unlisted so the next lookup asks Drive again
|
||||
// (`docs/BUGS.md` B135); the entry already has its new place.
|
||||
assert!(!fx.listed("a"));
|
||||
let st = fx.state();
|
||||
assert_eq!(st.entries[&a].parent, sub);
|
||||
assert_eq!(st.entries[&a].node.name, "b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_offline_rename_is_queued() {
|
||||
let fx = Fixture::new(false, false);
|
||||
fx.put(fx.dir, "a", false);
|
||||
let renamed = fx
|
||||
.namespace
|
||||
.rename(fx.dir, "a", fx.dir, "b", RenameFlags::default())
|
||||
.unwrap();
|
||||
assert_eq!(renamed, Renamed::Queued);
|
||||
assert_eq!(
|
||||
fx.calls(),
|
||||
[format!("queue rename {} to b authorized=false", uid("a"))]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rename_that_loses_the_link_is_queued() {
|
||||
let fx = Fixture::new(true, false);
|
||||
fx.put(fx.dir, "a", false);
|
||||
let renamed = fx
|
||||
.namespace
|
||||
.rename(fx.dir, "a", fx.dir, "b", RenameFlags::default())
|
||||
.unwrap();
|
||||
assert_eq!(renamed, Renamed::Queued);
|
||||
assert_eq!(
|
||||
fx.calls(),
|
||||
[
|
||||
format!("rename {} parent=- name=b", uid("a")),
|
||||
format!("queue rename {} to b authorized=false", uid("a")),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_folder_cannot_move_into_itself() {
|
||||
let fx = Fixture::new(true, true);
|
||||
let sub = fx.put(fx.dir, "sub", true);
|
||||
let inner = fx.put(sub, "inner", true);
|
||||
assert!(matches!(
|
||||
fx.namespace
|
||||
.rename(fx.dir, "sub", inner, "sub", RenameFlags::default()),
|
||||
Err(NamespaceError::InvalidArgument)
|
||||
));
|
||||
assert!(matches!(
|
||||
fx.namespace.rename(
|
||||
fx.dir,
|
||||
"sub",
|
||||
fx.dir,
|
||||
"other",
|
||||
RenameFlags {
|
||||
exchange: true,
|
||||
..RenameFlags::default()
|
||||
}
|
||||
),
|
||||
Err(NamespaceError::InvalidArgument)
|
||||
));
|
||||
assert!(fx.calls().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_replace_removes_nothing() {
|
||||
let fx = Fixture::new(true, true);
|
||||
fx.put(fx.dir, "a", false);
|
||||
let sub = fx.put(fx.dir, "sub", true);
|
||||
fx.put(sub, "inner", false);
|
||||
fx.put(fx.dir, "b", false);
|
||||
let no_replace = RenameFlags {
|
||||
no_replace: true,
|
||||
..RenameFlags::default()
|
||||
};
|
||||
assert!(matches!(
|
||||
fx.namespace.rename(fx.dir, "a", fx.dir, "b", no_replace),
|
||||
Err(NamespaceError::Exists)
|
||||
));
|
||||
assert!(matches!(
|
||||
fx.namespace
|
||||
.rename(fx.dir, "a", fx.dir, "sub", RenameFlags::default()),
|
||||
Err(NamespaceError::IsDirectory)
|
||||
));
|
||||
fx.put(fx.dir, "empty", true);
|
||||
assert!(matches!(
|
||||
fx.namespace
|
||||
.rename(fx.dir, "empty", fx.dir, "sub", RenameFlags::default()),
|
||||
Err(NamespaceError::NotEmpty)
|
||||
));
|
||||
assert!(fx.calls().is_empty());
|
||||
assert!(fx.db.open_replaces().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_replace_journals_before_removing_and_ends_the_entry() {
|
||||
let fx = Fixture::new(true, true);
|
||||
let a = fx.put(fx.dir, "a", false);
|
||||
fx.put(fx.dir, "b", false);
|
||||
let renamed = fx
|
||||
.namespace
|
||||
.rename(fx.dir, "a", fx.dir, "b", RenameFlags::default())
|
||||
.unwrap();
|
||||
assert_eq!(renamed, Renamed::Done);
|
||||
assert_eq!(
|
||||
fx.calls(),
|
||||
[
|
||||
format!("remove replaced {} journaled=true", uid("b")),
|
||||
format!("rename {} parent=- name=b", uid("a")),
|
||||
]
|
||||
);
|
||||
assert_eq!(fx.state().entries[&a].node.name, "b");
|
||||
// Ended when the rename returned.
|
||||
assert!(
|
||||
fx.db
|
||||
.state_str(&format!("replace:{}", uid("a")))
|
||||
.unwrap()
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_replace_drive_refuses_brings_the_victim_back() {
|
||||
let fx = Fixture::with(true, true, true);
|
||||
fx.put(fx.dir, "a", false);
|
||||
fx.put(fx.dir, "b", false);
|
||||
assert!(matches!(
|
||||
fx.namespace
|
||||
.rename(fx.dir, "a", fx.dir, "b", RenameFlags::default()),
|
||||
Err(NamespaceError::Host("refused"))
|
||||
));
|
||||
assert_eq!(
|
||||
fx.calls(),
|
||||
[
|
||||
format!("remove replaced {} journaled=true", uid("b")),
|
||||
format!("rename {} parent=- name=b", uid("a")),
|
||||
format!("restore {}", uid("b")),
|
||||
]
|
||||
);
|
||||
assert!(fx.listed("a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rename_whose_queued_create_vanished_asks_to_try_again() {
|
||||
// The recording host keeps no queue in the database, so the create
|
||||
// this local node stands for is gone, and Drive never landed it.
|
||||
let fx = Fixture::new(false, false);
|
||||
fx.namespace.create(fx.dir, "a").unwrap();
|
||||
fx.calls();
|
||||
assert!(matches!(
|
||||
fx.namespace
|
||||
.rename(fx.dir, "a", fx.dir, "b", RenameFlags::default()),
|
||||
Err(NamespaceError::Busy)
|
||||
));
|
||||
assert!(fx.calls().is_empty());
|
||||
assert!(fx.listed("a"));
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ graph TD
|
||||
| [`pdfs-store`](../crates/pdfs-store) | The SQLite schema and queries (`db/`), the content cache (`cache`) |
|
||||
| [`pdfs-drive`](../crates/pdfs-drive) | The `DriveApi` seam over the SDK, the call counter (`counted`), and `FakeDrive` for the simulations |
|
||||
| [`pdfs-sync`](../crates/pdfs-sync) | The mirror engine: its passes (`mirror`), split into the walks (`mirror::walk`), applying a plan (`mirror::apply`) and the push pass (`mirror::push`), its engine thread (`mirror::engine`), its reads and writes of the local disk in one module (`mirror::local`), and the parts with no I/O: planner, pass model and pass trace. It owns its state (`SyncParts`), reads and writes its tables only through `SyncStore`, and reaches the daemon only through `SyncHost` |
|
||||
| [`pdfs-vfs`](../crates/pdfs-vfs) | The mounted-files service, with no kernel adapter: the tree (`tree`: nodes, stable inodes, per-mount roots), the reserved inodes (`ids`), the open files (`open`: write handles and their authored ranges, released writes waiting for upload, directory handles, `fallocate` rules), the open-file service (`files`: open, write, resize, fsync and close, behind the `FilesHost` port), the namespace service (`namespace`: create, mkdir, unlink and rmdir behind the `NamespaceHost` port, and the settling of a cut-off replacing rename), and what the mount accepted but has not sent yet (`writes`: queued revisions, nodes removed here, echoes of our own changes). Errors are typed; the FUSE adapter maps them to errno |
|
||||
| [`pdfs-vfs`](../crates/pdfs-vfs) | The mounted-files service, with no kernel adapter: the tree (`tree`: nodes, stable inodes, per-mount roots), the reserved inodes (`ids`), the open files (`open`: write handles and their authored ranges, released writes waiting for upload, directory handles, `fallocate` rules), the open-file service (`files`: open, write, resize, fsync and close, behind the `FilesHost` port), the namespace service (`namespace`: create, mkdir, unlink, rmdir and rename behind the `NamespaceHost` port, and the settling of a cut-off replacing rename), and what the mount accepted but has not sent yet (`writes`: queued revisions, nodes removed here, echoes of our own changes). Errors are typed; the FUSE adapter maps them to errno |
|
||||
| [`pdfs-fuse`](../crates/pdfs-fuse) | The daemon: FUSE handlers (`filesystem`), finding nodes (`resolve`), folder listings and file sizes (`listing`, `sizes`), reads (`reads`), queueing and the drain (`enqueue`, `queue`, `drain`, `upload`), calls sent straight to Drive (`remote`), requests by path (`requests`), startup recovery (`recovery`), pins, search, trash, the shared tree (`shared`), the link state (`link`), remote events (`background`), the daemon's side of the sync engine (`sync`, which implements `SyncHost`), moves between locations (`relocate`), control handlers (`control`), push events (`events`), photos, sharing, devices, the supervisor, and the simulation tests (`sim/`) |
|
||||
| [`pdfs-daemon`](../crates/pdfs-daemon) | The daemon's composition root: waits for a session, opens the database and the content cache, resumes the session and mounts, then remounts or retries with a backoff and records each failure |
|
||||
| [`pdfs-cli`](../crates/pdfs-cli) | The `pdfs` binary. `pdfs daemon` runs `pdfs_daemon::run` in-process; every other command is a control-socket client |
|
||||
@@ -862,13 +862,13 @@ it to writing its sidecar, so overlapping fsyncs record in order (B301). What th
|
||||
from Drive and the upload queue goes through `files::FilesHost`, which `Core` implements; the
|
||||
FUSE callbacks keep the inode translation, the choice of thread and the reply.
|
||||
|
||||
The namespace service, `namespace::Namespace`, serves create, mkdir, unlink and rmdir: whether a
|
||||
The namespace service, `namespace::Namespace`, serves create, mkdir, unlink, rmdir and rename: whether a
|
||||
new node is made on Drive at once or queued, the parked create of a transient name, the POSIX
|
||||
checks on what `unlink` and `rmdir` may remove, and the order of a trash (Drive first, then the
|
||||
tree). Drive calls, the queue and the access rules go through `namespace::NamespaceHost`, which
|
||||
checks on what `unlink`, `rmdir` and a replacing rename may remove, the order of a trash (Drive
|
||||
first, then the tree), and the replace journal written before a rename removes its destination. Drive calls, the queue and the access rules go through `namespace::NamespaceHost`, which
|
||||
`Core` implements. The module also holds the rules that settle a replacing rename a stop cut off
|
||||
(B302). What still sits in `pdfs-fuse` around the tree is the code that fills it (listings,
|
||||
sizes, the drain), the read path, and rename.
|
||||
sizes, the drain) and the read path.
|
||||
|
||||
Steps 0 to 3 are 4.0.0. Steps 4 to 6 follow in 4.x, one service at a time. Out of scope for
|
||||
now: an encrypted local vault (full-disk encryption covers a copied disk today), Windows and
|
||||
|
||||
@@ -108,6 +108,7 @@ a live account since.
|
||||
|
||||
| Entry | Title |
|
||||
|---|---|
|
||||
| [B303](#b303--a-file-made-where-a-withdrawn-create-was-listed-refuses-every-write) | A file made where a withdrawn create was listed refuses every write |
|
||||
| [B302](#b302--a-stop-during-a-replacing-rename-leaves-the-replaced-file-in-the-trash) | A stop during a replacing rename leaves the replaced file in the trash |
|
||||
| [B301](#b301--two-overlapping-fsyncs-can-leave-the-older-ones-record-on-disk) | Two overlapping fsyncs can leave the older one's record on disk |
|
||||
| [B300](#b300--a-read-during-a-release-can-be-served-the-revision-the-write-replaced) | A read during a release can be served the revision the write replaced |
|
||||
@@ -405,6 +406,33 @@ a live account since.
|
||||
|
||||
Newest first.
|
||||
|
||||
### B303 — A file made where a withdrawn create was listed refuses every write
|
||||
|
||||
**Status:** Fixed (unverified)
|
||||
**Found:** 2026-11-27, from a CI failure of the `one_client_on_a_slow_link` simulation (seed 3):
|
||||
`rename y/d -> y/c.bin` answered EACCES, and the daemon log had two "access changed before the
|
||||
write could be queued" errors for the node.
|
||||
**Where:** `Core::trash_withdrawn_create` and `Core::drain_trash` in
|
||||
`crates/pdfs-fuse/src/drain/trash.rs`
|
||||
|
||||
**Repro:** Make a file and delete it while its create is on the wire, on a slow link. Drive makes
|
||||
the node and lists it before the drain has the answer. Refresh the folder in that window. Once the
|
||||
drain has trashed the node, make a file under the same name, write to it and rename it. The write
|
||||
is kept in staging with "access changed before the write could be queued", and the rename fails
|
||||
with EACCES.
|
||||
|
||||
**Cause.** The drain hid the node Drive made, so later listings left it out, but it did not take
|
||||
it out of a listing already in the tree. The refresh had put the node there under the deleted
|
||||
file's name. A new file under that name opened the existing entry, which was the node being
|
||||
trashed. Once the trash landed its row was gone, the node had no write authority, and every
|
||||
write and rename of it was refused.
|
||||
|
||||
**Fix.** `Core::withdraw_landed` hides the node and also removes it from every mount, and drops
|
||||
the kernel's entry for its name. Both places that trash a withdrawn create's node call it.
|
||||
|
||||
**Verified:** `a_listing_taken_while_a_withdrawn_create_lands_does_not_keep_it` holds the answer to
|
||||
a create, deletes the file, refreshes the folder, then lets the answer through. It fails without
|
||||
the fix and passes with it.
|
||||
### B302 — A stop during a replacing rename leaves the replaced file in the trash
|
||||
|
||||
**Status:** Fixed (unverified)
|
||||
|
||||
Reference in new issue
Block a user