only delete things older than current gen and update logic in doc as

well
This commit is contained in:
Matthew O'Gorman 2018-03-01 22:59:00 -05:00
parent 3c16044cb0
commit 467fdd8ca4
2 changed files with 14 additions and 9 deletions

View file

@ -1349,9 +1349,9 @@ special value <literal>old</literal> to delete all non-current
generations, a value such as <literal>30d</literal> to delete all generations, a value such as <literal>30d</literal> to delete all
generations older than the specified number of days (except for the generations older than the specified number of days (except for the
generation that was active at that point in time), or a value such as. generation that was active at that point in time), or a value such as.
<literal>+5</literal> to delete all but the number of items specified. <literal>+5</literal> to only keep the specified items older than the
Periodically deleting old generations is important to make garbage current generation. Periodically deleting old generations is important
collection effective.</para> to make garbage collection effective.</para>
</refsection> </refsection>

View file

@ -160,21 +160,26 @@ void deleteGenerations(const Path & profile, const std::set<unsigned int> & gens
void deleteGenerationsGreaterThan(const Path & profile, int max, bool dryRun) void deleteGenerationsGreaterThan(const Path & profile, int max, bool dryRun)
{ {
PathLocks lock; PathLocks lock;
lockProfile(lock, profile); lockProfile(lock, profile);
int curGen; int curGen;
bool fromCurGen = false;
Generations gens = findGenerations(profile, curGen); Generations gens = findGenerations(profile, curGen);
for (auto i = gens.rbegin(); i != gens.rend(); ++i) { for (auto i = gens.rbegin(); i != gens.rend(); ++i) {
if (i->number == curGen) {
fromCurGen = true;
max--;
continue;
}
if (fromCurGen) {
if (max) { if (max) {
max--; max--;
continue; continue;
} }
if (i->number != curGen)
deleteGeneration2(profile, i->number, dryRun); deleteGeneration2(profile, i->number, dryRun);
} }
} }
}
void deleteOldGenerations(const Path & profile, bool dryRun) void deleteOldGenerations(const Path & profile, bool dryRun)
{ {