-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Detect file reads that are longer than expected #24708
base: master
Are you sure you want to change the base?
Conversation
When Bazel knows the size of a file, it can also detect whether it would go past this size while reading the file. This is virtually free due to using a buffered stream and can catch cases of concurrent modifications or even bugs in Bazel.
@@ -844,16 +844,37 @@ public static String readContent(Path inputFile, Charset charset) throws IOExcep | |||
} | |||
|
|||
/** | |||
* Reads at most {@code limit} bytes from {@code inputFile} and returns it as a byte array. | |||
* Reads at most {@code limit} bytes from {@code inputFile} and returns them as a byte array. | |||
* | |||
* @throws IOException if there was an error. | |||
*/ | |||
public static byte[] readContentWithLimit(Path inputFile, int limit) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within Bazel, this function is now only called by tests. I can get rid of it if that's also the case for Blaze.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not used anywhere else internally. I guess we can get rid of it.
@@ -844,16 +844,37 @@ public static String readContent(Path inputFile, Charset charset) throws IOExcep | |||
} | |||
|
|||
/** | |||
* Reads at most {@code limit} bytes from {@code inputFile} and returns it as a byte array. | |||
* Reads at most {@code limit} bytes from {@code inputFile} and returns them as a byte array. | |||
* | |||
* @throws IOException if there was an error. | |||
*/ | |||
public static byte[] readContentWithLimit(Path inputFile, int limit) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not used anywhere else internally. I guess we can get rid of it.
985b05b
to
b132505
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -917,19 +881,27 @@ private LongReadIOException(Path path, int fileSize) { | |||
* the number of bytes read. | |||
* | |||
* <p>Use this method when you already know the size of the file. The check is intended to catch | |||
* issues where filesystems or external interference results in truncated or concurrently modified | |||
* files. | |||
* issues where filesystems or external interference results in truncated or concurrent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit [clarity]: Imo something like the following more clearly conveys the intended meaning while keeping your word choice. This is an optional suggestion, so feel free to ignore!
where the filesystem incorrectly returns truncated file contents, or where an external modification has concurrently truncated or appended to the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's clearer! Can you make the change during the import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
@meteorcloudy fyi since I'm not sure who is going to be mailed the internal CL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gTech will do the import, but I can suggest the edition, np!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I can just edit this PR, done ;)
@bazel-io fork 8.0.1 |
When Bazel knows the size of a file, it can also detect whether it would go past this size while reading the file. This is virtually free due to using a buffered stream and can catch cases of concurrent modifications or even bugs in Bazel.
Work towards #24694