Skip to content
Permalink
Browse files

JENKINS-10599 Publish over ssh with flatten creates empty directory

Only create the target directory when the first file is copied.
  • Loading branch information
oldelvet committed Aug 5, 2011
1 parent 4e3a5a3 commit ad1c610c6cd0fd3b01ad81a7549418d449f9291c
@@ -185,20 +185,24 @@ public void transferFile(final BPClient client, final FilePath filePath) throws
private final BPBuildInfo buildInfo;
private final BPClient client;
private final Set<String> flattenedFileNames = new LinkedHashSet<String>();
private boolean flattenResetCompleted;
private String previousPath;
private String relativeRemoteSubDirectory;

DirectoryMaker(final BPBuildInfo buildInfo, final BPClient client) throws IOException {
this.buildInfo = buildInfo;
this.client = client;
if (flatten) {
resetToSubDirectory();
}
}

public void changeAndMakeDirs(final FilePath filePath) throws IOException, InterruptedException {
if (flatten)
if (flatten) {
assertNotDuplicateFileName(filePath);
if (!flattenResetCompleted) {
// Only create target directory when there is a file to store
resetToSubDirectory();
flattenResetCompleted = true;
}
}
final String relPath = buildInfo.getRelativePath(filePath, removePrefix);
if (LOG.isDebugEnabled())
LOG.debug(Messages.log_pathToFile(filePath.getName(), relPath));
@@ -148,6 +148,13 @@ private void assertSingleFileInRoot(final String filename, final String pattern)
assertTransfer(transfer, expectedFileCount);
}

@Test public void testNoFiles() throws Exception {
final BPTransfer transfer = new BPTransfer("*.log", "", "", false, false);
// Should not change to/create initial directory on zero file transfer
final int expectedFileCount = 0;
assertTransfer(transfer, expectedFileCount);
}

@Test public void testEnvVarInPattern() throws Exception {
final RandomFile toTransfer = new RandomFile(baseDir.getRoot(), "hello_123.txt");
final BPTransfer transfer = new BPTransfer("hello_${BUILD_NUMBER}.*", "", "", false, false);
@@ -299,6 +306,14 @@ private void assertCreateDirectories(final RandomFile srcFile, final String remo
assertTransfer(transfer, 2);
}

@Test public void testCreateNoFilesWithDirectories() throws Exception {
final String remoteDir = "remote/root";
final BPTransfer transfer = new BPTransfer("**/*", remoteDir, "", false, false);

// Should not change to/create initial directory on zero file transfer
assertTransfer(transfer, 0);
}

@Test public void testFlatten() throws Exception {
final String srcPath1 = "bit/of/a/trek/to";
final String srcPath2 = "file/somewhere";
@@ -317,6 +332,14 @@ private void assertCreateDirectories(final RandomFile srcFile, final String remo
assertTransfer(transfer, 2);
}

@Test public void testFlattenWithNoFiles() throws Exception {
final String remoteDir = "remote/root";
final BPTransfer transfer = new BPTransfer("**/*", remoteDir, "", false, true);

// Should not change to/create initial directory on zero file transfer
assertTransfer(transfer, 0);
}

@Test(expected = BapPublisherException.class)
public void testFlattenThrowsExceptionIfTwoFilesHaveSameName() throws Exception {
final String srcPath1 = "bit/of/a/trek/to";
@@ -353,6 +376,15 @@ public void testFlattenThrowsExceptionIfTwoFilesHaveSameName() throws Exception
assertTransfer(transfer, 2);
}

@Test public void testRemovePrefixNoFiles() throws Exception {
final String prefix = "gonna/remove";

final BPTransfer transfer = new BPTransfer("**/*", "", prefix, false, false);

// Should not change to/create initial directory on zero file transfer
assertTransfer(transfer, 0);
}

@Test public void testRemovePrefixTrailingSlash() throws Exception {
final String prefix = "gonna/remove/";
final String srcPath1 = "but/not/this";

0 comments on commit ad1c610

Please sign in to comment.
You can’t perform that action at this time.