open.mp icon indicating copy to clipboard operation
open.mp copied to clipboard

`ftouch` clobbers files

Open Y-Less opened this issue 2 years ago • 2 comments
trafficstars

Describe the bug

The touch utility is meant to merely update a file's modified time, or create it if it doesn't exist, with no changes to the contents. ftouch should do the same, but seems to clobber the file contents. Really a pawn-lang bug.

To Reproduce

new File:f = fopen("moo.txt", io_write);
fwrite(f, "hi");
fclose(f);
ftouch("moo.txt");

Expected behavior

File contents should remain.

Y-Less avatar Nov 12 '23 21:11 Y-Less

I looked at the source:

https://github.com/openmultiplayer/compiler/blob/44ad6414c748466b8b37fdf1e1170959b98bb85b/source/amx/amxfile.c#L897

f=_tfopen(fullname,__T("wb"));
if (f!=NULL) {
    return fclose(f) == 0;
}

'wb' overwrites the file contents.

adib-yg avatar Nov 12 '23 22:11 adib-yg

Wouldn't the correct thing here be having ftouch only modify the file's time instead of rewriting it?

Hual avatar Dec 01 '23 10:12 Hual