Hack to fix #654 when utime fails on NAS
This commit is contained in:
@@ -3,9 +3,11 @@
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import stat
|
import stat
|
||||||
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import typing as t
|
import typing as t
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from datetime import datetime
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
@@ -151,6 +153,15 @@ class FileUtilMacOS(FileUtilABC):
|
|||||||
def utime(cls, path, times):
|
def utime(cls, path, times):
|
||||||
"""Set the access and modified time of path."""
|
"""Set the access and modified time of path."""
|
||||||
os.utime(path, times=times)
|
os.utime(path, times=times)
|
||||||
|
# verify the times were set correctly
|
||||||
|
# on some NAS devices, utime() may fail, see #654
|
||||||
|
stat_ = os.stat(path)
|
||||||
|
if int(stat_.st_atime) != int(times[0]) or int(stat_.st_mtime) != int(times[1]):
|
||||||
|
# try to use touch to set the times
|
||||||
|
# touch format for -t is [[CC]YY]MMDDhhmm[.SS]
|
||||||
|
# use the first time in times provides, this assumes both atime and mtime are the same
|
||||||
|
touch_time = datetime.fromtimestamp(times[0]).strftime("%Y%m%d%H%M.%S")
|
||||||
|
subprocess.run(["/usr/bin/touch", "-t", touch_time, path])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cmp(cls, f1, f2, mtime1=None):
|
def cmp(cls, f1, f2, mtime1=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user