Commit 8d09f565 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Avoid deleting extraneous local descriptor files.

DescriptorIndexCollector deletes descriptor files from a previous or
concurrent collect run if it doesn't collect those files itself.  This
is unexpected behavior and differs from what DescriptorCollectorImpl
does.

Fixes #20525.
parent c3079ae2
......@@ -7,6 +7,8 @@
- Unify the build process by adding git-submodule metrics-base in
src/build and removing all centralized parts of the build
process.
- Avoid deleting extraneous local descriptor files when collecting
descriptors from CollecTor.
# Changes in version 1.5.0 - 2016-10-19
......
......@@ -87,7 +87,8 @@ public class DescriptorIndexCollector implements DescriptorCollector {
if (deleteExtraneousLocalFiles) {
log.info("Deleting extraneous files from local directory {}.",
localDirectory);
deleteExtraneousLocalFiles(remoteFiles, localDirectory, localFiles);
deleteExtraneousLocalFiles(remoteDirectories, remoteFiles, localDirectory,
localFiles);
}
log.info("Finished descriptor collection.");
}
......@@ -138,15 +139,19 @@ public class DescriptorIndexCollector implements DescriptorCollector {
return true;
}
static void deleteExtraneousLocalFiles(
static void deleteExtraneousLocalFiles(String[] remoteDirectories,
SortedMap<String, FileNode> remoteFiles,
File localDir, SortedMap<String, Long> locals) {
for (String localPath : locals.keySet()) {
if (!remoteFiles.containsKey(localPath)) {
File extraneousLocalFile = new File(localDir, localPath);
log.debug("Deleting extraneous local file {}.",
extraneousLocalFile.getAbsolutePath());
extraneousLocalFile.delete();
for (String remoteDirectory : remoteDirectories) {
if (localPath.startsWith(remoteDirectory)) {
if (!remoteFiles.containsKey(localPath)) {
File extraneousLocalFile = new File(localDir, localPath);
log.debug("Deleting extraneous local file {}.",
extraneousLocalFile.getAbsolutePath());
extraneousLocalFile.delete();
}
}
}
}
}
......
......@@ -139,6 +139,8 @@ public class DescriptorIndexCollectorTest {
public void testNormalCollectingWithDeletion() throws Exception {
File localFolder = tmpf.newFolder();
makeStructure(localFolder, "1");
File nonSyncedDir = makeDirs(localFolder.toString(), "d");
makeFiles(nonSyncedDir, "p1");
File remoteDirectory = tmpf.newFolder();
makeStructure(remoteDirectory, "2");
......@@ -158,10 +160,10 @@ public class DescriptorIndexCollectorTest {
.collectDescriptors(indexFile.toURL().toString(),
new String[]{"a/b", "a/b/c"}, 1451606400_000L, localFolder, true);
// verify file addition.
// verify file addition, including that the non-synced dir is not touched.
checkContains(true,
DescriptorIndexCollector.statLocalDirectory(localFolder).toString(),
"a/b/y2", "a/b/x2", "a/b/c/u2");
"a/b/y2", "a/b/x2", "a/b/c/u2", "d/p1");
// verify that invalid files weren't fetched.
checkContains(false,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment