diff --git a/src/main/java/hudson/plugins/filesystem_scm/FolderDiff.java b/src/main/java/hudson/plugins/filesystem_scm/FolderDiff.java index 5d65180..9e352e9 100644 --- a/src/main/java/hudson/plugins/filesystem_scm/FolderDiff.java +++ b/src/main/java/hudson/plugins/filesystem_scm/FolderDiff.java @@ -152,14 +152,14 @@ public List getNewOrModifiedFiles(long time, boolean breakOnceFound) thro Iterator it = (Iterator) 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; @@ -168,7 +168,7 @@ public List getNewOrModifiedFiles(long time, boolean breakOnceFound) thro if (breakOnceFound) { return list; } - copyFile(file, tmp); + copyFile(sourceFile, destinationFile); } } } else { @@ -177,6 +177,23 @@ public List 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); diff --git a/src/test/java/hudson/plugins/filesystem_scm/FolderDiffTest.java b/src/test/java/hudson/plugins/filesystem_scm/FolderDiffTest.java index 1f6174e..8c41c03 100644 --- a/src/test/java/hudson/plugins/filesystem_scm/FolderDiffTest.java +++ b/src/test/java/hudson/plugins/filesystem_scm/FolderDiffTest.java @@ -154,6 +154,48 @@ public void getFilesNewOrModified_NewHiddenFileButIgnoreHidden_NoNewFile() throw assertMarkAsNewOrModified(new HashSet(), actualResult, diff); } + @Test + // Jenkins #49561 FeatureRequest + public void getFilesNewOrModifiedFiles_FileAttributesCanExecuteChanged_SourceFileModified() throws IOException { + // setup + Set expected = new HashSet(); + 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 expected = new HashSet(); + 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 expected = new HashSet(); + 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 @@ -188,5 +230,4 @@ private void assertMarkAsDelete(Set expected, File src, File d private FolderDiffFake getFolderDiff(File src, File dst) { return new FolderDiffFake(src.getAbsolutePath(), dst.getAbsolutePath()); } - }