Skip to content

Commit

Permalink
fix Issue 13758 - RDMD renames directory if -ofNAME is the name of a …
Browse files Browse the repository at this point in the history
…directory
  • Loading branch information
CyberShadow committed May 1, 2015
1 parent cc95b01 commit 7b655a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
24 changes: 14 additions & 10 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,23 @@ private int rebuild(string root, string fullExe,

// Delete the old executable before we start building.
yap("stat ", fullExe);
if (!dryRun && exists(fullExe))
if (exists(fullExe))
{
enforce(!isDir(fullExe), fullExe ~ " is a directory");
yap("rm ", fullExe);
try
remove(fullExe);
catch (FileException e)
if (!dryRun)
{
// This can occur on Windows if the executable is locked.
// Although we can't delete the file, we can still rename it.
auto oldExe = "%s.%s-%s.old".format(fullExe,
Clock.currTime.stdTime, thisProcessID);
yap("mv ", fullExe, " ", oldExe);
rename(fullExe, oldExe);
try
remove(fullExe);
catch (FileException e)
{
// This can occur on Windows if the executable is locked.
// Although we can't delete the file, we can still rename it.
auto oldExe = "%s.%s-%s.old".format(fullExe,
Clock.currTime.stdTime, thisProcessID);
yap("mv ", fullExe, " ", oldExe);
rename(fullExe, oldExe);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions rdmd_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ void runTests()
assert(res.status == 0, res.output);
assert(!res.output.canFind("compile_force_src"));
}

auto conflictDir = forceSrc.setExtension(".dir");
if (exists(conflictDir))
{
if (isFile(conflictDir))
remove(conflictDir);
else
rmdirRecurse(conflictDir);
}
mkdir(conflictDir);
res = execute([rdmdApp, compilerSwitch, "-of" ~ conflictDir, forceSrc]);
assert(res.status != 0, "-of set to a directory should fail");
}

void runConcurrencyTest()
Expand Down

0 comments on commit 7b655a1

Please sign in to comment.