coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

touch creating files newer than system clock

Open sunflsks opened this issue 5 years ago • 11 comments

I tried using the uutils and was compiling another piece of software from source with the ./configure && make && make install dance, when I got an error saying that the files were newer than system clock. Removing uutils from the PATH seemed to fix the issue. Is it a problem with touch?

sunflsks avatar Aug 31 '20 16:08 sunflsks

Would it be possible for you to provide some step to reproduce? It is too vague to be actionable now

sylvestre avatar Aug 31 '20 16:08 sylvestre

Could you run this and paste the results?

sudo strace uutils_touch /tmp/newfile &> log1.txt
sudo strace gnu_touch /tmp/newfile2 &> log2.txt

chadbrewbaker avatar Sep 03 '20 15:09 chadbrewbaker

Yeah, sure :) Just to clarify, here's what I get when I try to compile gnu sed from the tarball:

checking for a BSD-compatible install... /opt/uutils/bin/install -c
checking whether build environment is sane... configure: error: ls -t appears to fail.  Make sure there is not a broken
  alias in your environment
configure: error: newly created file is older than distributed files!
Check your system clock

sunflsks avatar Sep 03 '20 17:09 sunflsks

Sorry about that, my touchpad went a bit crazy. Here's the gnu touch strace:

sudhip@mr-coffee ~/logs> /bin/cat gtouch.txt
execve("/usr/bin/touch", ["/usr/bin/touch", "/tmp/newfile"], 0x7ffd04a206d8 /* 12 vars */) = 0
brk(NULL)                               = 0x55b80a681000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe28d985f0) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=179461, ...}) = 0
mmap(NULL, 179461, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6ca768d000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\202\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\364[g\253(\257\25\201\313\250\344q>\17\323\262"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2159552, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6ca768b000
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 1868448, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6ca74c2000
mmap(0x7f6ca74e8000, 1363968, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7f6ca74e8000
mmap(0x7f6ca7635000, 311296, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x173000) = 0x7f6ca7635000
mmap(0x7f6ca7681000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1be000) = 0x7f6ca7681000
mmap(0x7f6ca7687000, 12960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6ca7687000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6ca74c0000
arch_prctl(ARCH_SET_FS, 0x7f6ca768c600) = 0
mprotect(0x7f6ca7681000, 12288, PROT_READ) = 0
mprotect(0x55b8093d3000, 4096, PROT_READ) = 0
mprotect(0x7f6ca76e5000, 4096, PROT_READ) = 0
munmap(0x7f6ca768d000, 179461)          = 0
brk(NULL)                               = 0x55b80a681000
brk(0x55b80a6a2000)                     = 0x55b80a6a2000
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=3041456, ...}) = 0
mmap(NULL, 3041456, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6ca71d9000
close(3)                                = 0
openat(AT_FDCWD, "/tmp/newfile", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
dup2(3, 0)                              = 0
close(3)                                = 0
utimensat(0, NULL, NULL, 0)             = 0
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

and here's uutils touch:

sudhip@mr-coffee ~/logs> /bin/cat utouch.txt
execve("/opt/uutils/bin/touch", ["/opt/uutils/bin/touch", "/tmp/newfile"], 0x7ffded7590c8 /* 12 vars */) = 0
brk(NULL)                               = 0x55b6e6b09000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd9867f430) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=179461, ...}) = 0
mmap(NULL, 179461, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f9735256000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\22\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=18608, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9735254000
mmap(NULL, 20624, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f973524e000
mmap(0x7f973524f000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f973524f000
mmap(0x7f9735251000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f9735251000
mmap(0x7f9735252000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f9735252000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P7\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=39408, ...}) = 0
mmap(NULL, 43520, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9735243000
mmap(0x7f9735246000, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f9735246000
mmap(0x7f973524a000, 8192, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7000) = 0x7f973524a000
mmap(0x7f973524c000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8000) = 0x7f973524c000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\201\0\0\0\0\0\0"..., 832) = 832
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\307Y\373z\3054\277z\21\35\225\341\273\304<\223"..., 68, 824) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=158744, ...}) = 0
mmap(NULL, 135600, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9735221000
mmap(0x7f9735228000, 65536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7000) = 0x7f9735228000
mmap(0x7f9735238000, 20480, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f9735238000
mmap(0x7f973523d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b000) = 0x7f973523d000
mmap(0x7f973523f000, 12720, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f973523f000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 0\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=594704, ...}) = 0
mmap(NULL, 103144, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9735207000
mmap(0x7f973520a000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f973520a000
mmap(0x7f973521b000, 16384, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x7f973521b000
mmap(0x7f973521f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f973521f000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\202\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\364[g\253(\257\25\201\313\250\344q>\17\323\262"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2159552, ...}) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 1868448, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f973503e000
mmap(0x7f9735064000, 1363968, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7f9735064000
mmap(0x7f97351b1000, 311296, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x173000) = 0x7f97351b1000
mmap(0x7f97351fd000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1be000) = 0x7f97351fd000
mmap(0x7f9735203000, 12960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f9735203000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\363\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1332096, ...}) = 0
mmap(NULL, 1331224, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9734ef8000
mmap(0x7f9734f07000, 638976, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf000) = 0x7f9734f07000
mmap(0x7f9734fa3000, 626688, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xab000) = 0x7f9734fa3000
mmap(0x7f973503c000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x143000) = 0x7f973503c000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9734ef6000
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9734ef3000
arch_prctl(ARCH_SET_FS, 0x7f9734ef3900) = 0
mprotect(0x7f97351fd000, 12288, PROT_READ) = 0
mprotect(0x7f973503c000, 4096, PROT_READ) = 0
mprotect(0x7f973521f000, 4096, PROT_READ) = 0
mprotect(0x7f973523d000, 4096, PROT_READ) = 0
mprotect(0x7f973524c000, 4096, PROT_READ) = 0
mprotect(0x7f9735252000, 4096, PROT_READ) = 0
mprotect(0x55b6e6a3c000, 307200, PROT_READ) = 0
mprotect(0x7f97352ae000, 4096, PROT_READ) = 0
munmap(0x7f9735256000, 179461)          = 0
set_tid_address(0x7f9734ef3bd0)         = 24293
set_robust_list(0x7f9734ef3be0, 24)     = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x7f9735228b90, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7f97352350f0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7f9735228c30, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f97352350f0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f973507b6a0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
brk(NULL)                               = 0x55b6e6b09000
brk(0x55b6e6b2a000)                     = 0x55b6e6b2a000
openat(AT_FDCWD, "/proc/self/maps", O_RDONLY|O_CLOEXEC) = 3
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "55b6e5df4000-55b6e683c000 r-xp 0"..., 1024) = 1024
read(3, "usr/lib/libc-2.32.so\n7f973506400"..., 1024) = 1024
read(3, ".32.so\n7f9735228000-7f9735238000"..., 1024) = 1024
read(3, "bdl-2.32.so\n7f973524f000-7f97352"..., 1024) = 1024
close(3)                                = 0
sched_getaffinity(24293, 32, [0, 1, 2, 3]) = 32
rt_sigaction(SIGSEGV, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGSEGV, {sa_handler=0x55b6e639cc50, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0x7f97352350f0}, NULL, 8) = 0
rt_sigaction(SIGBUS, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGBUS, {sa_handler=0x55b6e639cc50, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0x7f97352350f0}, NULL, 8) = 0
sigaltstack(NULL, {ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9735280000
sigaltstack({ss_sp=0x7f9735280000, ss_flags=0, ss_size=8192}, NULL) = 0
getrandom("\xda\xec\xc2\x06\xdf\x95\x94\x2c\x2e\x45\xfa\x7e\x60\xcc\xa3\x06", 16, GRND_NONBLOCK) = 16
openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=3576, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=3576, ...}) = 0
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\7\0\0\0\7\0\0\0\0"..., 4096) = 3576
lseek(3, -2272, SEEK_CUR)               = 1304
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\7\0\0\0\7\0\0\0\0"..., 4096) = 2272
close(3)                                = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=3576, ...}) = 0
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
statx(AT_FDCWD, "/tmp/newfile", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffd9867ea20) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/tmp/newfile", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3
fcntl(3, F_GETFD)                       = 0x1 (flags FD_CLOEXEC)
close(3)                                = 0
sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=8192}, NULL) = 0
munmap(0x7f9735280000, 8192)            = 0
exit_group(0)                           = ?
+++ exited with 0 +++

sunflsks avatar Sep 03 '20 17:09 sunflsks

GNU touch

openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=3041456, ...}) = 0
mmap(NULL, 3041456, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6ca71d9000
close(3)                                = 0
openat(AT_FDCWD, "/tmp/newfile", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
dup2(3, 0)                              = 0
close(3)                                = 0
utimensat(0, NULL, NULL, 0)             = 0
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0

uutils touch

stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=3576, ...}) = 0
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
statx(AT_FDCWD, "/tmp/newfile", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffd9867ea20) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/tmp/newfile", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3
fcntl(3, F_GETFD)                       = 0x1 (flags FD_CLOEXEC)
close(3)

Why is it calling a stat on /etc/localtime? Also why are we using O_TRUNC|O_CLOEXEC instead of O_NOCTTY|O_NONBLOCK?

fnctl() https://www.man7.org/linux/man-pages/man2/fcntl.2.html utimensat() https://man7.org/linux/man-pages/man2/utimensat.2.html stat() https://man7.org/linux/man-pages/man2/stat.2.html statx() https://man7.org/linux/man-pages/man2/statx.2.html openat() https://man7.org/linux/man-pages/man2/open.2.html dup2() https://man7.org/linux/man-pages/man2/dup.2.html

chadbrewbaker avatar Sep 03 '20 18:09 chadbrewbaker

Problems I see:

  1. uutils_touch is truncating files by default - that's a problem?
  2. uutils_touch should also call utimensat()?

I'll run with code coverage to make sure I understand everything it is calling.

chadbrewbaker avatar Sep 03 '20 18:09 chadbrewbaker

So, I think that, in order to proceed, we need to nail down whether this is a touch issue or rust library issue.

My quick look at the touch code reveals nothing that looks incorrect about its logic or implementation. The integration tests are testing (and passing) for time correctness when setting the file times. And I see no obvious correlation in the rust code to the lower-level syscall differences. A more specific failure at the command line level would be helpful to design a test and move forward. Is there a way to more exactly tease out the process and failure condition of the failing compilation?

rivy avatar Sep 04 '20 04:09 rivy

This line: https://github.com/uutils/coreutils/blob/4b76849de72557e377bc211c82e6e5208d8bc652/src/uu/touch/src/touch.rs#L151

Library issue that hard codes the truncate(true).

https://github.com/rust-lang/rust/blob/4ffb5c5954a304daf47a567b34e74e421db86d98/library/std/src/fs.rs#L357

#[stable(feature = "rust1", since = "1.0.0")]
    pub fn create<P: AsRef<Path>>(path: P) -> io::Result<File> {
        OpenOptions::new().write(true).create(true).truncate(true).open(path.as_ref())
    }

GNU discussion on their design decisions for what flags to set: https://lists.gnu.org/archive/html/bug-coreutils/2018-10/msg00340.html

chadbrewbaker avatar Sep 04 '20 05:09 chadbrewbaker

I read through the referenced thread, but I don't see any direct discussion of the truncate option, unless it somehow equates with closing the file descriptor?

So, is the "truncate()" actually a problem? If it is, we could open the file using the same lower level code minus the truncate call (eg, OpenOptions::new().write(true).create(true).open(path.as_ref())). But, is it the cause of this issue?

rivy avatar Sep 04 '20 14:09 rivy

Just following up - is it still true that touch truncates files instead of just updating their mtime?

kevinburke1 avatar Oct 22 '20 21:10 kevinburke1

@kevinburkemeter the line that truncates files only does so if touch believes the file doesn't actually exist. There is a race condition in that the file could be created between the if condition and the call to File::create(), but generally you're not going to have a problem if you're using the utility normally.

This is still an issue that should be fixed, but it's not as bad as the previous comments made it sound.

Arcterus avatar Feb 21 '21 00:02 Arcterus