Skip to content

Commit

Permalink
FIX: WRITE on file-port does not update file size (posix fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Oct 3, 2021
1 parent 4127a7c commit 22de60c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/os/posix/dev-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ static int Get_File_Info(REBREQ *file)
***********************************************************************/
{
ssize_t num_bytes;
struct stat info;

if (!file->id) {
file->error = -RFE_NO_HANDLE;
Expand All @@ -512,8 +513,13 @@ static int Get_File_Info(REBREQ *file)
else file->error = -RFE_BAD_WRITE;
return DR_ERROR;
} else {
//SET_FLAG(file->modes, RFM_RESEEK);
file->actual = (u32)num_bytes;
}
if (fstat(file->id, &info) == 0) {
file->file.size = info.st_size;
file->file.time.l = (i32)(info.st_mtime);
}

return DR_DONE;
}
Expand Down
15 changes: 15 additions & 0 deletions src/tests/units/port-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ if system/platform = 'Windows [
--assert "Hella World! Goodbye World!" = to-string read/seek f 0
--assert port? close f
try [delete %file-552]
--assert all [
port? p: open/new %file-552
file? write p "a"
tail? read p
file? write p "b"
tail? read p
#{6162} = read/seek p 0
tail? read p
file? write/seek p "c" 0
#{62} = read p
#{6362} = read/seek p 0
2 = length? p
port? close p
]
try [delete %file-552]

--test-- "clear file port"
;@@ https://github.com/Oldes/Rebol-issues/issues/812
Expand Down

0 comments on commit 22de60c

Please sign in to comment.