Drop the block count in the garbage collector
This commit is contained in:
parent
967d066d8e
commit
01d56c1eec
|
@ -606,18 +606,17 @@ void getOwnership(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void deletePathWrapped(const Path & path,
|
void deletePathWrapped(const Path & path, unsigned long long & bytesFreed)
|
||||||
unsigned long long & bytesFreed, unsigned long long & blocksFreed)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
/* First try to delete it ourselves. */
|
/* First try to delete it ourselves. */
|
||||||
deletePath(path, bytesFreed, blocksFreed);
|
deletePath(path, bytesFreed);
|
||||||
} catch (SysError & e) {
|
} catch (SysError & e) {
|
||||||
/* If this failed due to a permission error, then try it with
|
/* If this failed due to a permission error, then try it with
|
||||||
the setuid helper. */
|
the setuid helper. */
|
||||||
if (haveBuildUsers() && !amPrivileged()) {
|
if (haveBuildUsers() && !amPrivileged()) {
|
||||||
getOwnership(path);
|
getOwnership(path);
|
||||||
deletePath(path, bytesFreed, blocksFreed);
|
deletePath(path, bytesFreed);
|
||||||
} else
|
} else
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
@ -626,8 +625,8 @@ void deletePathWrapped(const Path & path,
|
||||||
|
|
||||||
void deletePathWrapped(const Path & path)
|
void deletePathWrapped(const Path & path)
|
||||||
{
|
{
|
||||||
unsigned long long dummy1, dummy2;
|
unsigned long long dummy1;
|
||||||
deletePathWrapped(path, dummy1, dummy2);
|
deletePathWrapped(path, dummy1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -425,10 +425,9 @@ bool LocalStore::isActiveTempFile(const GCState & state,
|
||||||
void LocalStore::deleteGarbage(GCState & state, const Path & path)
|
void LocalStore::deleteGarbage(GCState & state, const Path & path)
|
||||||
{
|
{
|
||||||
printMsg(lvlInfo, format("deleting `%1%'") % path);
|
printMsg(lvlInfo, format("deleting `%1%'") % path);
|
||||||
unsigned long long bytesFreed, blocksFreed;
|
unsigned long long bytesFreed;
|
||||||
deletePathWrapped(path, bytesFreed, blocksFreed);
|
deletePathWrapped(path, bytesFreed);
|
||||||
state.results.bytesFreed += bytesFreed;
|
state.results.bytesFreed += bytesFreed;
|
||||||
state.results.blocksFreed += blocksFreed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -304,8 +304,7 @@ void getOwnership(const Path & path);
|
||||||
|
|
||||||
/* Like deletePath(), but changes the ownership of `path' using the
|
/* Like deletePath(), but changes the ownership of `path' using the
|
||||||
setuid wrapper if necessary (and possible). */
|
setuid wrapper if necessary (and possible). */
|
||||||
void deletePathWrapped(const Path & path,
|
void deletePathWrapped(const Path & path, unsigned long long & bytesFreed);
|
||||||
unsigned long long & bytesFreed, unsigned long long & blocksFreed);
|
|
||||||
|
|
||||||
void deletePathWrapped(const Path & path);
|
void deletePathWrapped(const Path & path);
|
||||||
|
|
||||||
|
|
|
@ -494,7 +494,7 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
|
|
||||||
results.paths = readStrings<PathSet>(from);
|
results.paths = readStrings<PathSet>(from);
|
||||||
results.bytesFreed = readLongLong(from);
|
results.bytesFreed = readLongLong(from);
|
||||||
results.blocksFreed = readLongLong(from);
|
readLongLong(from); // obsolete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,13 +65,9 @@ struct GCResults
|
||||||
number of bytes that would be or was freed. */
|
number of bytes that would be or was freed. */
|
||||||
unsigned long long bytesFreed;
|
unsigned long long bytesFreed;
|
||||||
|
|
||||||
/* The number of file system blocks that would be or was freed. */
|
|
||||||
unsigned long long blocksFreed;
|
|
||||||
|
|
||||||
GCResults()
|
GCResults()
|
||||||
{
|
{
|
||||||
bytesFreed = 0;
|
bytesFreed = 0;
|
||||||
blocksFreed = 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -297,8 +297,7 @@ void computePathSize(const Path & path,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _deletePath(const Path & path, unsigned long long & bytesFreed,
|
static void _deletePath(const Path & path, unsigned long long & bytesFreed)
|
||||||
unsigned long long & blocksFreed)
|
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
|
@ -308,10 +307,8 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed,
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode) || S_ISREG(st.st_mode)) makeMutable(path);
|
if (S_ISDIR(st.st_mode) || S_ISREG(st.st_mode)) makeMutable(path);
|
||||||
|
|
||||||
if (!S_ISDIR(st.st_mode) && st.st_nlink == 1) {
|
if (!S_ISDIR(st.st_mode) && st.st_nlink == 1)
|
||||||
bytesFreed += st.st_size;
|
bytesFreed += st.st_blocks * 512;
|
||||||
blocksFreed += st.st_blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
Strings names = readDirectory(path);
|
Strings names = readDirectory(path);
|
||||||
|
@ -323,7 +320,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
||||||
_deletePath(path + "/" + *i, bytesFreed, blocksFreed);
|
_deletePath(path + "/" + *i, bytesFreed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remove(path.c_str()) == -1)
|
if (remove(path.c_str()) == -1)
|
||||||
|
@ -333,19 +330,17 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed,
|
||||||
|
|
||||||
void deletePath(const Path & path)
|
void deletePath(const Path & path)
|
||||||
{
|
{
|
||||||
unsigned long long dummy1, dummy2;
|
unsigned long long dummy;
|
||||||
deletePath(path, dummy1, dummy2);
|
deletePath(path, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void deletePath(const Path & path, unsigned long long & bytesFreed,
|
void deletePath(const Path & path, unsigned long long & bytesFreed)
|
||||||
unsigned long long & blocksFreed)
|
|
||||||
{
|
{
|
||||||
startNest(nest, lvlDebug,
|
startNest(nest, lvlDebug,
|
||||||
format("recursively deleting path `%1%'") % path);
|
format("recursively deleting path `%1%'") % path);
|
||||||
bytesFreed = 0;
|
bytesFreed = 0;
|
||||||
blocksFreed = 0;
|
_deletePath(path, bytesFreed);
|
||||||
_deletePath(path, bytesFreed, blocksFreed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,7 @@ void computePathSize(const Path & path,
|
||||||
returns the number of bytes and blocks freed. */
|
returns the number of bytes and blocks freed. */
|
||||||
void deletePath(const Path & path);
|
void deletePath(const Path & path);
|
||||||
|
|
||||||
void deletePath(const Path & path, unsigned long long & bytesFreed,
|
void deletePath(const Path & path, unsigned long long & bytesFreed);
|
||||||
unsigned long long & blocksFreed);
|
|
||||||
|
|
||||||
/* Make a path read-only recursively. */
|
/* Make a path read-only recursively. */
|
||||||
void makePathReadOnly(const Path & path);
|
void makePathReadOnly(const Path & path);
|
||||||
|
|
|
@ -544,10 +544,9 @@ static void opCheckValidity(Strings opFlags, Strings opArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static string showBytes(unsigned long long bytes, unsigned long long blocks)
|
static string showBytes(unsigned long long bytes)
|
||||||
{
|
{
|
||||||
return (format("%d bytes (%.2f MiB, %d blocks)")
|
return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str();
|
||||||
% bytes % (bytes / (1024.0 * 1024.0)) % blocks).str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -562,7 +561,7 @@ struct PrintFreed
|
||||||
if (show)
|
if (show)
|
||||||
cout << format("%1% store paths deleted, %2% freed\n")
|
cout << format("%1% store paths deleted, %2% freed\n")
|
||||||
% results.paths.size()
|
% results.paths.size()
|
||||||
% showBytes(results.bytesFreed, results.blocksFreed);
|
% showBytes(results.bytesFreed);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -735,7 +734,7 @@ static void showOptimiseStats(OptimiseStats & stats)
|
||||||
{
|
{
|
||||||
printMsg(lvlError,
|
printMsg(lvlError,
|
||||||
format("%1% freed by hard-linking %2% files; there are %3% files with equal contents out of %4% files in total")
|
format("%1% freed by hard-linking %2% files; there are %3% files with equal contents out of %4% files in total")
|
||||||
% showBytes(stats.bytesFreed, stats.blocksFreed)
|
% showBytes(stats.bytesFreed)
|
||||||
% stats.filesLinked
|
% stats.filesLinked
|
||||||
% stats.sameContents
|
% stats.sameContents
|
||||||
% stats.totalFiles);
|
% stats.totalFiles);
|
||||||
|
|
|
@ -503,7 +503,7 @@ static void performOp(unsigned int clientVersion,
|
||||||
|
|
||||||
writeStrings(results.paths, to);
|
writeStrings(results.paths, to);
|
||||||
writeLongLong(results.bytesFreed, to);
|
writeLongLong(results.bytesFreed, to);
|
||||||
writeLongLong(results.blocksFreed, to);
|
writeLongLong(0, to); // obsolete
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue