Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to work around the delete-on-close bug in Dokan. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions fuse4win-070d3a2e43de/src/docanfuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "ScopeGuard.h"
#include "docanfuse.h"
#include <stdio.h>
#include <set>
#include <string>

#ifdef __CYGWIN__
#define FWPRINTF dummy_fwprintf
Expand All @@ -21,6 +23,9 @@ int dummy_fwprintf(FILE*, const wchar_t*, ...)

HINSTANCE hFuseDllInstance;

// hack to work around delete-on-close bug in Dokan
static std::set<std::wstring> delete_on_close_files;

extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH) {
Expand Down Expand Up @@ -62,7 +67,20 @@ static int DOKAN_CALLBACK FuseCleanup(
if (impl->debug()) FWPRINTF(stderr, L"Cleanup: %s\n\n", FileName);

impl_chain_guard guard(impl,DokanFileInfo->ProcessId);
return -errno_to_win32_error(impl->cleanup(FileName,DokanFileInfo));

std::set<std::wstring>::iterator it = delete_on_close_files.find(FileName);
if (it == delete_on_close_files.end()) {
return -errno_to_win32_error(impl->cleanup(FileName,DokanFileInfo));
}
else {
delete_on_close_files.erase(it);
if (DokanFileInfo->IsDirectory) {
return -errno_to_win32_error(impl->delete_directory(FileName,DokanFileInfo));
}
else {
return -errno_to_win32_error(impl->delete_file(FileName,DokanFileInfo));
}
}
}

static int DOKAN_CALLBACK FuseCreateDirectory(
Expand Down Expand Up @@ -199,10 +217,15 @@ static int DOKAN_CALLBACK FuseCreateFile(
FWPRINTF(stderr, L"\tFlags: %u (0x%x)\n", FlagsAndAttributes, FlagsAndAttributes);
fflush(stderr);
}

impl_chain_guard guard(impl,DokanFileInfo->ProcessId);
return -win_error(impl->create_file(FileName,AccessMode,ShareMode,

int err = -win_error(impl->create_file(FileName,AccessMode,ShareMode,
CreationDisposition,FlagsAndAttributes,DokanFileInfo));
if (err == 0 && FlagsAndAttributes & FILE_FLAG_DELETE_ON_CLOSE) {
delete_on_close_files.insert(std::wstring(FileName));
}
return err;
}

static int DOKAN_CALLBACK FuseCloseFile(
Expand Down