On Thu, 13 Mar 2008 02:11:29 +0500, Andrey Rahmatullin wrote: > > $ ls -la --time-style=full-iso test.txt > > -rw-r--r-- 1 builder builder 0 2008-03-12 23:47:55.737319000 +0300 test.txt > > $ python test.py > > $ ls -la --time-style=full-iso test.txt > > -rw-r--r-- 1 builder builder 0 2008-03-12 23:47:55.737318000 +0300 test.txt > Ох. > Это баг в os.utime? Налицо две проблемы: 1. stat(2) оперирует с точностью до наносекунд (struct stat: st_mtim.tv_nsec), а utimes(2) - до милисекунд (struct timeval: tv_usec). Так что сравнивать время модификации файла до и после utimes со стороны test_archivemail.py неосмотрительно =). 2. комбинация os.path.getmtime/os.utime таки не просто округляет время до меньшего, но умудряется иногда терять милисекунду: $ touch test.txt $ ls -la --time-style=full-iso test.txt -rw-r--r-- 1 bga bga 0 2008-03-13 22:16:55.793640217 +0300 test.txt $ python ~/test.py $ ls -la --time-style=full-iso test.txt -rw-r--r-- 1 bga bga 0 2008-03-13 22:16:55.793640000 +0300 test.txt $ python ~/test.py $ ls -la --time-style=full-iso test.txt -rw-r--r-- 1 bga bga 0 2008-03-13 22:16:55.793639000 +0300 test.txt $ python ~/test.py $ ls -la --time-style=full-iso test.txt -rw-r--r-- 1 bga bga 0 2008-03-13 22:16:55.793638000 +0300 test.txt $ python ~/test.py $ ls -la --time-style=full-iso test.txt -rw-r--r-- 1 bga bga 0 2008-03-13 22:16:55.793637000 +0300 test.txt $ gcc -Wall -g -o ~/test ~/test.c $ ~/test $ ls -la --time-style=full-iso test.txt -rw-r--r-- 1 bga bga 0 2008-03-13 22:16:55.793637000 +0300 test.txt $ ~/test $ ls -la --time-style=full-iso test.txt -rw-r--r-- 1 bga bga 0 2008-03-13 22:16:55.793637000 +0300 test.txt -------------- $ cat ~/test.py #!/usr/bin/python import os file = "test.txt" mtime = os.path.getmtime(file) atime = os.path.getatime(file) os.utime(file, (atime, mtime)) -------------- $ cat ~/test.c #include #include #include #include #include #include #include int errno; int main(int argc, char *argv[]) { struct timeval tvp[3]; char filename[] = "test.txt"; struct stat st; if (stat(filename, &st) == -1) { perror("stat"); return -1; } tvp[0].tv_sec = st.st_atim.tv_sec; tvp[0].tv_usec = st.st_atim.tv_nsec/1000; tvp[1].tv_sec = st.st_mtim.tv_sec; tvp[1].tv_usec = st.st_mtim.tv_nsec/1000; tvp[2].tv_sec = st.st_ctim.tv_sec; tvp[2].tv_usec = st.st_ctim.tv_nsec/1000; if (utimes(filename, tvp) == -1) perror("utimes"); return 0; } -- Grigory Batalov, ALT Linux Team