diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-01-11 19:26:33 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-01-11 19:26:33 +0300 |
commit | 472ccc420343b7fe3463445dafad60f130cf027e (patch) | |
tree | a7f18387b83ee863e90683857e4caf995d20b007 /tests/test_files.sh | |
parent | aea3d3db46634bf26298c8df0be020c03b80daba (diff) |
Fixed file truncation without writes
In the open call, the LFS_O_TRUNC flag was correctly zeroing the file, but
it wasn't actually writing the change out to disk. This went unnoticed because
in the cases where the truncate was followed by a file write, the
updated contents would be written out correctly.
Marking the file as dirty if the file isn't already truncated fixes the
problem with the least impact. Also added better test cases around
truncating files.
Diffstat (limited to 'tests/test_files.sh')
-rwxr-xr-x | tests/test_files.sh | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/test_files.sh b/tests/test_files.sh index 6086107..4443463 100755 --- a/tests/test_files.sh +++ b/tests/test_files.sh @@ -34,7 +34,8 @@ tests/test.py << TEST lfs_size_t chunk = 31; srand(0); lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "$2", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_open(&lfs, &file[0], "$2", + ${3:-LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC}) => 0; for (lfs_size_t i = 0; i < size; i += chunk) { chunk = (chunk < size - i) ? chunk : size - i; for (lfs_size_t b = 0; b < chunk; b++) { @@ -53,7 +54,10 @@ tests/test.py << TEST lfs_size_t chunk = 29; srand(0); lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "$2", LFS_O_RDONLY) => 0; + lfs_stat(&lfs, "$2", &info) => 0; + info.type => LFS_TYPE_REG; + info.size => size; + lfs_file_open(&lfs, &file[0], "$2", ${3:-LFS_O_RDONLY}) => 0; for (lfs_size_t i = 0; i < size; i += chunk) { chunk = (chunk < size - i) ? chunk : size - i; lfs_file_read(&lfs, &file[0], buffer, chunk) => chunk; @@ -78,10 +82,27 @@ echo "--- Large file test ---" w_test $LARGESIZE largeavacado r_test $LARGESIZE largeavacado +echo "--- Zero file test ---" +w_test 0 noavacado +r_test 0 noavacado + +echo "--- Truncate small test ---" +w_test $SMALLSIZE mediumavacado +r_test $SMALLSIZE mediumavacado +w_test $MEDIUMSIZE mediumavacado +r_test $MEDIUMSIZE mediumavacado + +echo "--- Truncate zero test ---" +w_test $SMALLSIZE noavacado +r_test $SMALLSIZE noavacado +w_test 0 noavacado +r_test 0 noavacado + echo "--- Non-overlap check ---" r_test $SMALLSIZE smallavacado r_test $MEDIUMSIZE mediumavacado r_test $LARGESIZE largeavacado +r_test 0 noavacado echo "--- Dir check ---" tests/test.py << TEST @@ -105,6 +126,10 @@ tests/test.py << TEST strcmp(info.name, "largeavacado") => 0; info.type => LFS_TYPE_REG; info.size => $LARGESIZE; + lfs_dir_read(&lfs, &dir[0], &info) => 1; + strcmp(info.name, "noavacado") => 0; + info.type => LFS_TYPE_REG; + info.size => 0; lfs_dir_read(&lfs, &dir[0], &info) => 0; lfs_dir_close(&lfs, &dir[0]) => 0; lfs_unmount(&lfs) => 0; |