Skip to content

Commit 438d0b1

Browse files
Reverting another debug statement.
Change test to just do a rename and not a delete.
1 parent d936456 commit 438d0b1

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

src/org/labkey/test/TestFileUtils.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,28 @@ public static void deleteDir(File dir)
446446
}
447447
}
448448

449+
/**
450+
* Rename a directory.
451+
* @param sourceDir the directory to rename
452+
* @param newDirName the new name for the directory
453+
*/
449454
public static void renameDir(Path sourceDir, String newDirName)
450455
{
451-
LOG.info("Renaming " + sourceDir + " to " + newDirName);
456+
LOG.info("Renaming {} to {}", sourceDir, newDirName);
457+
458+
// Check if the directory is outside the test enlistment.
452459
checkFileLocation(sourceDir.toFile());
460+
453461
Assert.assertTrue(sourceDir + " does not exists.", sourceDir.toFile().exists());
454462

455463
try
456464
{
465+
// Get the separator appropriate for the given OS.
457466
String separator = File.separator;
458-
Path newDir = Paths.get(sourceDir.toString().substring(0, sourceDir.toString().lastIndexOf(separator)) + separator + newDirName);
467+
int lastIndex = sourceDir.toString().lastIndexOf(separator);
468+
Path newDir = lastIndex <= 0 ?
469+
Paths.get(separator + newDirName) :
470+
Paths.get(sourceDir.toString().substring(0, lastIndex) + separator + newDirName);
459471
Files.move(sourceDir, newDir);
460472
LOG.info("Rename successful.");
461473
}
@@ -472,7 +484,7 @@ private static void checkFileLocation(File file)
472484
if (!FileUtils.directoryContains(getLabKeyRoot(), file))
473485
{
474486
// TODO: Consider throwing IllegalArgumentException
475-
LOG.info("DEBUG: Attempting to delete a file outside of test enlistment: " + getLabKeyRoot());
487+
LOG.info("DEBUG: Attempting to delete / rename a file outside of test enlistment: " + getLabKeyRoot());
476488
}
477489
}
478490
catch (IOException ignore) { }

src/org/labkey/test/tests/assay/AssayTransformMissingParentDirTest.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,10 @@ public void testMissingParentDirectoryRegression() throws Exception
5151
getArtifactCollector().dumpPageSnapshot("TransformScript_Added");
5252
assayDesignerPage.clickSave();
5353

54-
// Now delete, or rename, the parent dir to ensure we handle it reasonably
55-
if (SystemUtils.IS_OS_WINDOWS)
56-
{
57-
// Deleting directories on Windows is not always reliable, try renaming as an alternative.
58-
String newName = "Not-Here-" + Instant.now().getEpochSecond();
59-
TestFileUtils.renameDir(parentDir, newName);
60-
}
61-
else
62-
{
63-
TestFileUtils.deleteDir(parentDir.toFile());
64-
}
54+
// Now rename the parent dir to ensure we handle it reasonably. Deleting directories on Windows is not always
55+
// timely, renaming the directory will have the same effect.
56+
String newName = "Not-Here-" + Instant.now().getEpochSecond();
57+
TestFileUtils.renameDir(parentDir, newName);
6558

6659
Assert.assertFalse(String.format("Directory %s is still present.", parentDir),
6760
FileUtils.isDirectory(parentDir.toFile()));

src/org/labkey/test/util/RReportHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public boolean executeScriptDirectly(String script, String expectedLines, boolea
160160
return checkScriptOutput(scriptOutput, expectedLines, failOnError);
161161
}
162162

163-
public boolean checkScriptOutput(String scriptOutput, String expectedLines, boolean failOnError)
163+
private boolean checkScriptOutput(String scriptOutput, String expectedLines, boolean failOnError)
164164
{
165165
if (failOnError && doesScriptProduceError(scriptOutput))
166166
return false;

0 commit comments

Comments
 (0)