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

FSBlobContainer leniently truncates #15579

Closed
rmuir opened this issue Dec 21, 2015 · 1 comment
Closed

FSBlobContainer leniently truncates #15579

rmuir opened this issue Dec 21, 2015 · 1 comment
Labels

Comments

@rmuir
Copy link
Contributor

rmuir commented Dec 21, 2015

The two write methods are defined like this:

    public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
        final Path file = path.resolve(blobName);
        try (OutputStream outputStream = Files.newOutputStream(file)) {
            ...

Passing nothing to Files.newOutputStream will truncate the output file if its already there:

If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn't exist, or initially truncating an existing regular-file to a size of 0 if it exists. 

Can we please pass StandardOpenOptions.CREATE_NEW so that silent data truncation never happens?

@s1monw
Copy link
Contributor

s1monw commented Dec 21, 2015

Can we please pass StandardOpenOptions.CREATE_NEW so that silent data truncation never happens?

+100

@clintongormley clintongormley added help wanted adoptme good first issue low hanging fruit labels Feb 29, 2016
abeyad pushed a commit to abeyad/elasticsearch that referenced this issue Apr 20, 2016
This commit contains the following:
  1. Clarifies the behavior that must be adhered to by any implementors
of the BlobContainer interface.  This is done through expanded Javadocs.
  2. BlobContainer#writeBlob cannot overwrite an already existing blob.
It will now throw an exception if trying to write to a pre-existing
file.

Closes elastic#15579
Closes elastic#15580
abeyad pushed a commit to abeyad/elasticsearch that referenced this issue Aug 2, 2016
conform with the requirements of the writeBlob method by
throwing a FileAlreadyExistsException if attempting to write
to a blob that already exists. This change means implementations
of BlobContainer should never overwrite blobs - to overwrite a
blob, it must first be deleted and then can be written again.

Closes elastic#15579
abeyad pushed a commit that referenced this issue Aug 2, 2016
conform with the requirements of the writeBlob method by
throwing a FileAlreadyExistsException if attempting to write
to a blob that already exists. This change means implementations
of BlobContainer should never overwrite blobs - to overwrite a
blob, it must first be deleted and then can be written again.

Closes #15579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants