mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 13:06:01 +01:00
deletePath(): Keep going when encountering an undeletable file
This should reduce the impact of #5207.
This commit is contained in:
parent
44bdb74c62
commit
665e76f2e5
1 changed files with 16 additions and 4 deletions
|
|
@ -414,7 +414,7 @@ void recursiveSync(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _deletePath(Descriptor parentfd, const std::filesystem::path & path, uint64_t & bytesFreed)
|
static void _deletePath(Descriptor parentfd, const std::filesystem::path & path, uint64_t & bytesFreed, std::exception_ptr & ex)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
@ -472,7 +472,7 @@ static void _deletePath(Descriptor parentfd, const std::filesystem::path & path,
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
std::string childName = dirent->d_name;
|
std::string childName = dirent->d_name;
|
||||||
if (childName == "." || childName == "..") continue;
|
if (childName == "." || childName == "..") continue;
|
||||||
_deletePath(dirfd(dir.get()), path + "/" + childName, bytesFreed);
|
_deletePath(dirfd(dir.get()), path + "/" + childName, bytesFreed, ex);
|
||||||
}
|
}
|
||||||
if (errno) throw SysError("reading directory %1%", path);
|
if (errno) throw SysError("reading directory %1%", path);
|
||||||
}
|
}
|
||||||
|
|
@ -480,7 +480,14 @@ static void _deletePath(Descriptor parentfd, const std::filesystem::path & path,
|
||||||
int flags = S_ISDIR(st.st_mode) ? AT_REMOVEDIR : 0;
|
int flags = S_ISDIR(st.st_mode) ? AT_REMOVEDIR : 0;
|
||||||
if (unlinkat(parentfd, name.c_str(), flags) == -1) {
|
if (unlinkat(parentfd, name.c_str(), flags) == -1) {
|
||||||
if (errno == ENOENT) return;
|
if (errno == ENOENT) return;
|
||||||
throw SysError("cannot unlink %1%", path);
|
try {
|
||||||
|
throw SysError("cannot unlink %1%", path);
|
||||||
|
} catch (...) {
|
||||||
|
if (!ex)
|
||||||
|
ex = std::current_exception();
|
||||||
|
else
|
||||||
|
ignoreExceptionExceptInterrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// TODO implement
|
// TODO implement
|
||||||
|
|
@ -500,7 +507,12 @@ static void _deletePath(const std::filesystem::path & path, uint64_t & bytesFree
|
||||||
throw SysError("opening directory '%1%'", path);
|
throw SysError("opening directory '%1%'", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
_deletePath(dirfd.get(), path, bytesFreed);
|
std::exception_ptr ex;
|
||||||
|
|
||||||
|
_deletePath(dirfd.get(), path, bytesFreed, ex);
|
||||||
|
|
||||||
|
if (ex)
|
||||||
|
std::rethrow_exception(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue