Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to make PathRef robust against concurrent filesystem modifications #2832

Merged
merged 4 commits into from
Oct 9, 2023
Merged
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
50 changes: 30 additions & 20 deletions main/api/src/mill/api/PathRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,38 @@ object PathRef {
val sub = path.subRelativeTo(basePath)
digest.update(sub.toString().getBytes())
if (!attrs.isDir) {
if (isPosix) {
updateWithInt(os.perms(path, followLinks = false).value)
}
if (quick) {
val value = (attrs.mtime, attrs.size).hashCode()
updateWithInt(value)
} else if (jnio.Files.isReadable(path.toNIO)) {
val is =
try Some(os.read.inputStream(path))
catch {
case _: jnio.FileSystemException =>
// This is known to happen, when we try to digest a socket file.
// We ignore the content of this file for now, as we would do,
// when the file isn't readable.
// See https://github.com/com-lihaoyi/mill/issues/1875
None
}
is.foreach {
Using.resource(_) { is =>
StreamSupport.stream(is, digestOut)
try {
if (isPosix) {
updateWithInt(os.perms(path, followLinks = false).value)
}
if (quick) {
val value = (attrs.mtime, attrs.size).hashCode()
updateWithInt(value)
} else if (jnio.Files.isReadable(path.toNIO)) {
val is =
try Some(os.read.inputStream(path))
catch {
case _: jnio.FileSystemException =>
// This is known to happen, when we try to digest a socket file.
// We ignore the content of this file for now, as we would do,
// when the file isn't readable.
// See https://github.com/com-lihaoyi/mill/issues/1875
None
}
is.foreach {
Using.resource(_) { is =>
StreamSupport.stream(is, digestOut)
}
}
}
} catch {
case e: java.nio.file.NoSuchFileException =>
// If file was deleted after we listed the folder but before we operate on it,
// `os.perms` or `os.read.inputStream` will crash. In that case, just do nothing,
// so next time we calculate the `PathRef` we'll get a different hash signature
// (either with the file missing, or with the file present) and invalidate any
// caches

}
}
}
Expand Down