Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d0909b

Browse files
committed
Implemented FSCatalogInfo structure support, and used this to implement
FSSpec.SetDates() and GetDates(). Closes #662836.
1 parent a5caa6f commit 2d0909b

3 files changed

Lines changed: 32 additions & 17 deletions

File tree

Lib/plat-mac/macfs.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@
2121
WRITE = 2
2222
smAllScripts = -3
2323

24+
#
25+
# Find the epoch conversion for file dates in a way that works on OS9 and OSX
26+
import time
27+
if time.gmtime(0)[0] == 1970:
28+
_EPOCHCONVERT = -((1970-1904)*365 + 17) * (24*60*60) + 0x100000000L
29+
def _utc2time(utc):
30+
t = utc[1] + _EPOCHCONVERT
31+
return int(t)
32+
def _time2utc(t):
33+
t = t - _EPOCHCONVERT
34+
if t < -0x7fffffff:
35+
t = t + 0x10000000L
36+
return (0, int(t), 0)
37+
else:
38+
def _utc2time(utc): return utc[1]
39+
def _time2utc(t): return (0, t, 0)
40+
2441
# The old name of the error object:
2542
error = Carbon.File.Error
2643

@@ -52,12 +69,20 @@ def SetFInfo(self, info):
5269
return self.FSpSetFInfo(info)
5370

5471
def GetDates(self):
55-
import os
56-
statb = os.stat(self.as_pathname())
57-
return statb.st_ctime, statb.st_mtime, 0
72+
catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
73+
catinfo, d1, d2, d3 = FSRef(self).FSGetCatalogInfo(catInfoFlags)
74+
cdate = catinfo.createDate
75+
mdate = catinfo.contentModDate
76+
bdate = catinfo.backupDate
77+
return _utc2time(cdate), _utc2time(mdate), _utc2time(bdate)
5878

59-
def SetDates(self, *dates):
60-
pass # print "FSSpec.SetDates not yet implemented"
79+
def SetDates(self, cdate, mdate, bdate):
80+
catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
81+
catinfo = Carbon.File.FSCatalogInfo(
82+
createDate = _time2utc(cdate),
83+
contentModDate = _time2utc(mdate),
84+
backupDate = _time2utc(bdate))
85+
FSRef(self).FSSetCatalogInfo(catInfoFlags, catinfo)
6186

6287
class FSRef(Carbon.File.FSRef):
6388
def as_fsspec(self):

Mac/Modules/file/_Filemodule.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ static int FSCatalogInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
370370
"atributeModDate",
371371
"accessDate",
372372
"backupDate",
373-
"permissions",
374373
"valence",
375374
"dataLogicalSize",
376375
"dataPhysicalSize",
@@ -380,7 +379,7 @@ static int FSCatalogInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
380379
"userPrivileges"
381380
, 0};
382381

383-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|HhllO&O&O&O&O&(llll)llllllb", kw, &((FSCatalogInfoObject *)self)->ob_itself.nodeFlags,
382+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|HhllO&O&O&O&O&llllllb", kw, &((FSCatalogInfoObject *)self)->ob_itself.nodeFlags,
384383
&((FSCatalogInfoObject *)self)->ob_itself.volume,
385384
&((FSCatalogInfoObject *)self)->ob_itself.parentDirID,
386385
&((FSCatalogInfoObject *)self)->ob_itself.nodeID,
@@ -389,10 +388,6 @@ static int FSCatalogInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
389388
UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.attributeModDate,
390389
UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.accessDate,
391390
UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.backupDate,
392-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[0],
393-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[1],
394-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[2],
395-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[3],
396391
&((FSCatalogInfoObject *)self)->ob_itself.valence,
397392
&((FSCatalogInfoObject *)self)->ob_itself.dataLogicalSize,
398393
&((FSCatalogInfoObject *)self)->ob_itself.dataPhysicalSize,

Mac/Modules/file/filesupport.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class FSCatalogInfoDefinition(PEP253Mixin, ObjectDefinition):
413413
),
414414
]
415415
# The same info, but in a different form
416-
INITFORMAT = "HhllO&O&O&O&O&(llll)llllllb"
416+
INITFORMAT = "HhllO&O&O&O&O&llllllb"
417417
INITARGS = """&((FSCatalogInfoObject *)self)->ob_itself.nodeFlags,
418418
&((FSCatalogInfoObject *)self)->ob_itself.volume,
419419
&((FSCatalogInfoObject *)self)->ob_itself.parentDirID,
@@ -423,10 +423,6 @@ class FSCatalogInfoDefinition(PEP253Mixin, ObjectDefinition):
423423
UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.attributeModDate,
424424
UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.accessDate,
425425
UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.backupDate,
426-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[0],
427-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[1],
428-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[2],
429-
&((FSCatalogInfoObject *)self)->ob_itself.permissions[3],
430426
&((FSCatalogInfoObject *)self)->ob_itself.valence,
431427
&((FSCatalogInfoObject *)self)->ob_itself.dataLogicalSize,
432428
&((FSCatalogInfoObject *)self)->ob_itself.dataPhysicalSize,
@@ -444,7 +440,6 @@ class FSCatalogInfoDefinition(PEP253Mixin, ObjectDefinition):
444440
"atributeModDate",
445441
"accessDate",
446442
"backupDate",
447-
"permissions",
448443
"valence",
449444
"dataLogicalSize",
450445
"dataPhysicalSize",

0 commit comments

Comments
 (0)