codekingpro/portable-devtools
114k
1import os2 3 4def load_ctime_functions():5 if os.name == "nt":6 import win32_setctime7 8 def get_ctime_windows(filepath):9 return os.stat(filepath).st_ctime10 11 def set_ctime_windows(filepath, timestamp):12 if not win32_setctime.SUPPORTED:13 return14 15 try:16 win32_setctime.setctime(filepath, timestamp)17 except (OSError, ValueError):18 pass19 20 return get_ctime_windows, set_ctime_windows21 22 if hasattr(os.stat_result, "st_birthtime"):23 24 def get_ctime_macos(filepath):25 return os.stat(filepath).st_birthtime26 27 def set_ctime_macos(filepath, timestamp):28 pass29 30 return get_ctime_macos, set_ctime_macos31 32 if hasattr(os, "getxattr") and hasattr(os, "setxattr"):33 34 def get_ctime_linux(filepath):35 try:36 return float(os.getxattr(filepath, b"user.loguru_crtime"))37 except OSError:38 return os.stat(filepath).st_mtime39 40 def set_ctime_linux(filepath, timestamp):41 try:42 os.setxattr(filepath, b"user.loguru_crtime", str(timestamp).encode("ascii"))43 except OSError:44 pass45 46 return get_ctime_linux, set_ctime_linux47 48 def get_ctime_fallback(filepath):49 return os.stat(filepath).st_mtime50 51 def set_ctime_fallback(filepath, timestamp):52 pass53 54 return get_ctime_fallback, set_ctime_fallback55 56 57get_ctime, set_ctime = load_ctime_functions()58 