We have a directory “bin” which, because of processes outside of our direct control, might contain broken symlinks. We have a task ‘deleteBrokenSymlinksFromBin’ to attempt to clear these out:
task deleteBrokenSymlinksFromBin {
doLast {
File binDir = new File("${rootDir}/install/server/x64/bin")
binDir.listFiles()
.collect { it.toPath() }
.findAll { Files.isSymbolicLink(it) && !Files.exists(it) }
.each {
try {
logger.info("Deleting broken symlink on path ${it}")
Files.delete(it)
} catch (Exception e) {
logger.error("There was an error deleting a symlink from bin ${it}")
}
}
}
}
)
We have a Copy task, “deployBin” which depends on deleteBrokenSymlinksFromBin. On Linux this task reports “Could not read path” errors mentioning paths of symlinks the previous task should have deleted.
Should the above code work? We’re struggling to reason about exactly when the inputs/outputs on the copy task are populated & evaluated.
// Log
:workgroup:deployBin FAILED [17:09:39][BuildServer] [17:09:39][BuildServer] FAILURE: Build failed with an exception. [17:09:39][BuildServer] [17:09:39][BuildServer] * What went wrong: [17:09:39][BuildServer] Could not read path '/data/tc/near/shared/install/server/x64/bin/.libtabmixins.so.debug.caUR6r'. [17:09:39][BuildServer] > /data/tc/near/shared/install/server/x64/bin/.libtabmixins.so.debug.caUR6r [17:09:39][BuildServer]