# HG changeset patch # User Paul Boddie # Date 1647731841 -3600 # Node ID 9eb56e5f2691297cb59531e1b3af7ba58428e50b # Parent e35acec6b7768023d83da784f6a2865322f870dc Truncate existing files when overwriting. diff -r e35acec6b776 -r 9eb56e5f2691 libe2access/host/op_copy_in.c --- a/libe2access/host/op_copy_in.c Sat Mar 19 00:41:11 2022 +0100 +++ b/libe2access/host/op_copy_in.c Sun Mar 20 00:17:21 2022 +0100 @@ -64,6 +64,11 @@ if (ext2fs_file_open(fs, ino_file, flags, &file)) return 1; + /* Truncate the file, if overwriting. */ + + if (!(flags & EXT2_FILE_CREATE)) + ext2fs_file_set_size2(file, 0); + /* Open the file in the source directory. */ fp = fopen(filename, "r"); @@ -146,7 +151,7 @@ /* Without a basename, the target exists and is either a directory, into which the source file shall be copied, or it is a file that shall be - overwritten. */ + overwritten (for which the basename is irrelevant). */ if (basename == NULL) {