Cleaned up fileutil, rolled back changes for #654

This commit is contained in:
Rhet Turnbull
2022-03-11 06:06:21 -08:00
parent d26b625d57
commit 84a96bd4d0

View File

@@ -3,11 +3,9 @@
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
@@ -153,15 +151,6 @@ 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):