Skip to content

Commit

Permalink
Retry failed rmdirs (they're almost always due to temporary conditions)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Feb 21, 2012
1 parent cb81027 commit e2d91da
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions dustmite.d
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,29 @@ string applyReductionToPath(string path, Reduction reduction)
return path;
}

void safeRmdirRecurse(string dir)
{
while (true)
try
{
rmdirRecurse(dir);
return;
}
catch (Exception e)
{
writeln("Error while rmdir-ing " ~ dir ~ ": " ~ e.msg);
import core.thread;
Thread.sleep(dur!"seconds"(1));
writeln("Retrying...");
}
}

void safeSave(int[] address, string savedir)
{
auto tempdir = savedir ~ ".inprogress"; scope(failure) rmdirRecurse(tempdir);
if (exists(tempdir)) rmdirRecurse(tempdir);
auto tempdir = savedir ~ ".inprogress"; scope(failure) safeRmdirRecurse(tempdir);
if (exists(tempdir)) safeRmdirRecurse(tempdir);
save(Reduction(Reduction.Type.None), tempdir);
if (exists(savedir)) rmdirRecurse(savedir);
if (exists(savedir)) safeRmdirRecurse(savedir);
rename(tempdir, savedir);
}

Expand Down Expand Up @@ -454,7 +471,7 @@ bool test(Reduction reduction)
}

string testdir = dir ~ ".test";
measure!"testSave"({save(reduction, testdir);}); scope(exit) measure!"clean"({rmdirRecurse(testdir);});
measure!"testSave"({save(reduction, testdir);}); scope(exit) measure!"clean"({safeRmdirRecurse(testdir);});

auto lastdir = getcwd(); scope(exit) chdir(lastdir);
chdir(testdir);
Expand Down

0 comments on commit e2d91da

Please sign in to comment.