forked from lix-project/lix
* Use deletePathWrapped() in more places.
This commit is contained in:
parent
fa33303146
commit
5f681988f2
|
@ -531,14 +531,28 @@ void getOwnership(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void deletePathWrapped(const Path & path)
|
void deletePathWrapped(const Path & path,
|
||||||
|
unsigned long long & bytesFreed)
|
||||||
{
|
{
|
||||||
/* When using build users and we're not root, we may not have
|
try {
|
||||||
sufficient permission to delete the path. So use the setuid
|
/* First try to delete it ourselves. */
|
||||||
helper to change ownership to us. */
|
deletePath(path, bytesFreed);
|
||||||
if (haveBuildUsers() && !amPrivileged())
|
} catch (SysError & e) {
|
||||||
getOwnership(path);
|
/* If this failed due to a permission error, then try it with
|
||||||
deletePath(path);
|
the setuid helper. */
|
||||||
|
if (haveBuildUsers() && !amPrivileged()) {
|
||||||
|
getOwnership(path);
|
||||||
|
deletePath(path, bytesFreed);
|
||||||
|
} else
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void deletePathWrapped(const Path & path)
|
||||||
|
{
|
||||||
|
unsigned long long dummy;
|
||||||
|
deletePathWrapped(path, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -637,7 +637,7 @@ Path LocalStore::addToStore(const Path & _srcPath, bool fixed,
|
||||||
|
|
||||||
if (!isValidPath(dstPath)) {
|
if (!isValidPath(dstPath)) {
|
||||||
|
|
||||||
if (pathExists(dstPath)) deletePath(dstPath);
|
if (pathExists(dstPath)) deletePathWrapped(dstPath);
|
||||||
|
|
||||||
copyPath(srcPath, dstPath);
|
copyPath(srcPath, dstPath);
|
||||||
|
|
||||||
|
@ -673,7 +673,7 @@ Path LocalStore::addTextToStore(const string & suffix, const string & s,
|
||||||
|
|
||||||
if (!isValidPath(dstPath)) {
|
if (!isValidPath(dstPath)) {
|
||||||
|
|
||||||
if (pathExists(dstPath)) deletePath(dstPath);
|
if (pathExists(dstPath)) deletePathWrapped(dstPath);
|
||||||
|
|
||||||
writeStringToFile(dstPath, s);
|
writeStringToFile(dstPath, s);
|
||||||
|
|
||||||
|
@ -710,18 +710,7 @@ void deleteFromStore(const Path & _path, unsigned long long & bytesFreed)
|
||||||
}
|
}
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
||||||
try {
|
deletePathWrapped(path, bytesFreed);
|
||||||
/* First try to delete it ourselves. */
|
|
||||||
deletePath(path, bytesFreed);
|
|
||||||
} catch (SysError & e) {
|
|
||||||
/* If this failed due to a permission error, then try it with
|
|
||||||
the setuid helper. */
|
|
||||||
if (haveBuildUsers() && !amPrivileged()) {
|
|
||||||
getOwnership(path);
|
|
||||||
deletePath(path, bytesFreed);
|
|
||||||
} else
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,12 @@ bool amPrivileged();
|
||||||
/* Recursively change the ownership of `path' to the current uid. */
|
/* Recursively change the ownership of `path' to the current uid. */
|
||||||
void getOwnership(const Path & path);
|
void getOwnership(const Path & path);
|
||||||
|
|
||||||
|
/* Like deletePath(), but changes the ownership of `path' using the
|
||||||
|
setuid wrapper if necessary (and possible). */
|
||||||
|
void deletePathWrapped(const Path & path,
|
||||||
|
unsigned long long & bytesFreed);
|
||||||
|
|
||||||
|
void deletePathWrapped(const Path & path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue