Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/main/java/hudson/plugins/filesystem_scm/FolderDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ public List<Entry> getNewOrModifiedFiles(long time, boolean breakOnceFound) thro
Iterator<File> it = (Iterator<File>) FileUtils.iterateFiles(src, createAntPatternFileFilter(),
getDirFilter());
while (it.hasNext()) {
File file = it.next();
String relativeName = getRelativeName(file.getAbsolutePath(), src.getAbsolutePath());
File sourceFile = it.next();
String relativeName = getRelativeName(sourceFile.getAbsolutePath(), src.getAbsolutePath());
// need to change dst to see if there is such a file
File tmp = new File(dst, relativeName);
File destinationFile = new File(dst, relativeName);
boolean newOrModified = true;
if (!tmp.exists()) {// new
if (isNew(destinationFile)) {// new
list.add(createAndLogg(relativeName, Entry.Type.NEW));
} else if (FileUtils.isFileNewer(file, time) || FileUtils.isFileNewer(file, tmp)) { // modified
} else if (isModified(time, sourceFile, destinationFile)) { // modified
list.add(createAndLogg(relativeName, Entry.Type.MODIFIED));
} else {
newOrModified = false;
Expand All @@ -168,7 +168,7 @@ public List<Entry> getNewOrModifiedFiles(long time, boolean breakOnceFound) thro
if (breakOnceFound) {
return list;
}
copyFile(file, tmp);
copyFile(sourceFile, destinationFile);
}
}
} else {
Expand All @@ -177,6 +177,23 @@ public List<Entry> getNewOrModifiedFiles(long time, boolean breakOnceFound) thro
return list;
}

private boolean isNew(File tmp) {
return !tmp.exists();
}

private boolean isModified(long time, File sourceFile, File destinationFile) {
boolean sourcIsNewerThenLastModificationDate = FileUtils.isFileNewer(sourceFile, time);
boolean sourceIsNewerThenDestination = FileUtils.isFileNewer(sourceFile, destinationFile);
// jenkins #49561
boolean readableAttributeDiffers = sourceFile.canRead() != destinationFile.canRead();
boolean writableAttributeDiffers = sourceFile.canWrite() != destinationFile.canWrite();
boolean executableAttributeDiffers = sourceFile.canExecute() != destinationFile.canExecute();
boolean isHiddenAttributeDiffers = sourceFile.isHidden() != destinationFile.isHidden();
boolean attributeChanged = readableAttributeDiffers || writableAttributeDiffers || executableAttributeDiffers
|| isHiddenAttributeDiffers;
return sourcIsNewerThenLastModificationDate || sourceIsNewerThenDestination || attributeChanged;
}

private Entry createAndLogg(String relativeName, Type type) {
log(type.name() + " file: " + relativeName);
return new Entry(relativeName, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,48 @@ public void getFilesNewOrModified_NewHiddenFileButIgnoreHidden_NoNewFile() throw
assertMarkAsNewOrModified(new HashSet<FolderDiff.Entry>(), actualResult, diff);
}

@Test
// Jenkins #49561 FeatureRequest
public void getFilesNewOrModifiedFiles_FileAttributesCanExecuteChanged_SourceFileModified() throws IOException {
// setup
Set<FolderDiff.Entry> expected = new HashSet<FolderDiff.Entry>();
expected.add(new Entry(folderFilePath, FolderDiff.Entry.Type.MODIFIED));
File folderFile = new File(src, folderFilePath);

Assert.assertTrue(folderFile.exists());
folderFile.setExecutable(!folderFile.canExecute());

assertMarkAsNewOrModified(expected, currentTestExecutionTime, src, dst);
}

@Test
// Jenkins #49561 FeatureRequest
public void getFilesNewOrModifiedFiles_FileAttributesCanReadChanged_SourceFileModified() throws IOException {
// setup
Set<FolderDiff.Entry> expected = new HashSet<FolderDiff.Entry>();
expected.add(new Entry(folderFilePath, FolderDiff.Entry.Type.MODIFIED));
File folderFile = new File(src, folderFilePath);

Assert.assertTrue(folderFile.exists());
folderFile.setReadable(!folderFile.canRead());

assertMarkAsNewOrModified(expected, currentTestExecutionTime, src, dst);
}

@Test
// Jenkins #49561 FeatureRequest
public void getFilesNewOrModifiedFiles_FileAttributesCanWriteChanged_SourceFileModified() throws IOException {
// setup
Set<FolderDiff.Entry> expected = new HashSet<FolderDiff.Entry>();
expected.add(new Entry(folderFilePath, FolderDiff.Entry.Type.MODIFIED));
File folderFile = new File(src, folderFilePath);

Assert.assertTrue(folderFile.exists());
folderFile.setWritable(!folderFile.canWrite());

assertMarkAsNewOrModified(expected, currentTestExecutionTime, src, dst);
}

private void hideFile(String hiddenFilePathString) throws IOException {
File hiddenFile = new File(src, hiddenFilePathString);
// Windows specific code
Expand Down Expand Up @@ -188,5 +230,4 @@ private void assertMarkAsDelete(Set<FolderDiff.Entry> expected, File src, File d
private FolderDiffFake getFolderDiff(File src, File dst) {
return new FolderDiffFake(src.getAbsolutePath(), dst.getAbsolutePath());
}

}