Skip to content

Bug: Uploading a shorter file after uploading a bigger file doesn't truncate it #7

Closed
@MrYakobo

Description

@MrYakobo

The bug: By uploading a shorter file after uploading a bigger file, the original file bytes are still there.
Expected behaviour: The new file should be truncated first.

To reproduce

Caddyfile

{
    order upload before file_server
}

http://localhost {
    root * ./uploads

    upload method POST {
        dest_dir ./uploads
        file_field_name f
        max_filesize 512M
    }
}
echo '{"yo": "this is my original file, that is pretty long"}' > my_file.json
curl -F f=@my_file.json http://localhost
echo '{"yo": "this is short"}' > my_file.json
curl -F f=@my_file.json http://localhost
cat ./uploads/my_file.json
{"yo": "this is short"}inal file, that is pretty long"}

Obviously, I expected the output {"yo": "this is short"} instead of a broken JSON file.

Possible errendous line

tempFile, tmpf_err := os.OpenFile(u.DestDir+"/"+handler.Filename, os.O_RDWR|os.O_CREATE, 0755)

Adding os.O_TRUNC to the options may fix the issue. I've not tested it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions