diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1996-09-15 22:13:26 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1996-09-15 22:13:26 (GMT) |
commit | 57d53a90d92e83f7d3a72d5c775be9f52aa0d89c (patch) | |
tree | 2c3bdd638a7958951d412dc54511aeed0f8daa1f /Mac | |
parent | df34cf120619ac394bce7f66b270f14af14a41b2 (diff) | |
download | cpython-57d53a90d92e83f7d3a72d5c775be9f52aa0d89c.zip cpython-57d53a90d92e83f7d3a72d5c775be9f52aa0d89c.tar.gz cpython-57d53a90d92e83f7d3a72d5c775be9f52aa0d89c.tar.bz2 |
- Optionally copy file times for copy/copytree (default on)
- Added touch(file) routine to tell the finder a files icon or
something has changed (*finally* found out how to do this)
Diffstat (limited to 'Mac')
-rw-r--r-- | Mac/Lib/macostools.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Mac/Lib/macostools.py b/Mac/Lib/macostools.py index da1e3ab..46eef98 100644 --- a/Mac/Lib/macostools.py +++ b/Mac/Lib/macostools.py @@ -9,6 +9,7 @@ import Res import os from MACFS import * import MacOS +import time try: openrf = MacOS.openrf except AttributeError: @@ -52,7 +53,18 @@ def mkdirs(dst): mkdirs(head) os.mkdir(dst, 0777) -def copy(src, dst, createpath=0): +def touched(dst): + """Tell the finder a file has changed""" + file_fss = macfs.FSSpec(dst) + vRefNum, dirID, name = file_fss.as_tuple() + dir_fss = macfs.FSSpec((vRefNum, dirID, '')) + crdate, moddate, bkdate = dir_fss.GetDates() + now = time.time() + if now == moddate: + now = now + 1 + dir_fss.SetDates(crdate, now, bkdate) + +def copy(src, dst, createpath=0, copydates=1): """Copy a file, including finder info, resource fork, etc""" if createpath: mkdirs(os.path.split(dst)[0]) @@ -82,13 +94,17 @@ def copy(src, dst, createpath=0): df.Creator, df.Type = sf.Creator, sf.Type df.Flags = (sf.Flags & (kIsStationary|kNameLocked|kHasBundle|kIsInvisible|kIsAlias)) dstfss.SetFInfo(df) + if copydates: + crdate, mddate, bkdate = srcfss.GetDates() + dstfss.SetDates(crdate, mddate, bkdate) + touched(dstfss) -def copytree(src, dst): +def copytree(src, dst, copydates=1): """Copy a complete file tree to a new destination""" if os.path.isdir(src): mkdirs(dst) files = os.listdir(src) for f in files: - copytree(os.path.join(src, f), os.path.join(dst, f)) + copytree(os.path.join(src, f), os.path.join(dst, f), copydates) else: - copy(src, dst, 1) + copy(src, dst, 1, copydates) |