Cygwin, correct delete

When deleting a file, Windows first opens it, deletes it, and closes it.
But Windows does not allow deleting opened files, so no need to check before deletion.
This commit is contained in:
benrubson 2018-03-26 22:19:06 +02:00
parent 89215f16c5
commit be0c616d38

View File

@ -739,7 +739,9 @@ int DirNode::unlink(const char *plaintextName) {
Lock _lock(mutex); Lock _lock(mutex);
int res = 0; // Windows does not allow deleting opened files, so no need to check
// There is this "issue" however : https://github.com/billziss-gh/winfsp/issues/157
#ifndef __CYGWIN__
if ((ctx != nullptr) && ctx->lookupNode(plaintextName)) { if ((ctx != nullptr) && ctx->lookupNode(plaintextName)) {
// If FUSE is running with "hard_remove" option where it doesn't // If FUSE is running with "hard_remove" option where it doesn't
// hide open files for us, then we can't allow an unlink of an open // hide open files for us, then we can't allow an unlink of an open
@ -747,15 +749,17 @@ int DirNode::unlink(const char *plaintextName) {
RLOG(WARNING) << "Refusing to unlink open file: " << cyName RLOG(WARNING) << "Refusing to unlink open file: " << cyName
<< ", hard_remove option " << ", hard_remove option "
"is probably in effect"; "is probably in effect";
res = -EBUSY; return -EBUSY;
} else { }
#endif
int res = 0;
string fullName = rootDir + cyName; string fullName = rootDir + cyName;
res = ::unlink(fullName.c_str()); res = ::unlink(fullName.c_str());
if (res == -1) { if (res == -1) {
res = -errno; res = -errno;
VLOG(1) << "unlink error: " << strerror(-res); VLOG(1) << "unlink error: " << strerror(-res);
} }
}
return res; return res;
} }