Skip to content

Commit

Permalink
Dokan: Ensure moving a file awaits until the file is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed May 3, 2024
1 parent a1caf58 commit 7864d15
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions vfs/src/dokan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ impl VirtualFilesystem {
) {
tracing::trace!("enter");

// We need to lock `self.handles` here to prevent anything from opening the file while this
// function runs. It is because if the file is marked for removal here and if some other
// function opens the file, then the function `self.repo.remove_entry` will fail with
// `Error::Locked`.
// Also see this issue: https://github.com/equalitie/ouisync-app/issues/414
let mut handles = self.handles.lock().await;

match &context.entry {
Entry::File(entry) => {
let mut file_lock = entry.file.lock().await;
Expand All @@ -412,12 +419,6 @@ impl VirtualFilesystem {
Entry::Directory(_) => (),
};

// We need to lock `self.handles` here to prevent anything from opening the file while this
// function runs. It is because if the file is marked for removal here and if some other
// function opens the file, then the function `self.repo.remove_entry` will fail with
// `Error::Locked`.
let mut handles = self.handles.lock().await;

if let Some(to_delete) = self
.close_shared(context.entry.shared(), &mut handles)
.await
Expand Down

0 comments on commit 7864d15

Please sign in to comment.