New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
touch creating files newer than system clock #1592
Comments
Would it be possible for you to provide some step to reproduce? |
Could you run this and paste the results? sudo strace uutils_touch /tmp/newfile &> log1.txt
sudo strace gnu_touch /tmp/newfile2 &> log2.txt |
Yeah, sure :) Just to clarify, here's what I get when I try to compile gnu
|
Sorry about that, my touchpad went a bit crazy. Here's the gnu touch strace:
and here's uutils touch:
|
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 |
Problems I see:
I'll run with code coverage to make sure I understand everything it is calling. |
So, I think that, in order to proceed, we need to nail down whether this is a My quick look at the |
This line: coreutils/src/uu/touch/src/touch.rs Line 151 in 4b76849
Library issue that hard codes the truncate(true). #[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 |
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, |
Just following up - is it still true that |
@kevinburkemeter the line that truncates files only does so if This is still an issue that should be fixed, but it's not as bad as the previous comments made it sound. |
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 withtouch
?The text was updated successfully, but these errors were encountered: