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

Skip to content

Commit 0bdf979

Browse files
committed
Added [GS]etDates methods to get and set creation, modification and
backup times.
1 parent a39a25e commit 0bdf979

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Mac/Modules/macfsmodule.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,54 @@ mfs_GetFSSpecFSSpec(self)
347347
return NULL;
348348
}
349349

350+
/*
351+
** Two generally useful routines
352+
*/
353+
static OSErr
354+
PyMac_GetFileDates(fss, crdat, mddat, bkdat)
355+
FSSpec *fss;
356+
unsigned long *crdat, *mddat, *bkdat;
357+
{
358+
CInfoPBRec pb;
359+
OSErr error;
360+
361+
pb.dirInfo.ioNamePtr = fss->name;
362+
pb.dirInfo.ioFDirIndex = 0;
363+
pb.dirInfo.ioVRefNum = fss->vRefNum;
364+
pb.dirInfo.ioDrDirID = fss->parID;
365+
error = PBGetCatInfoSync(&pb);
366+
if ( error ) return error;
367+
*crdat = pb.hFileInfo.ioFlCrDat;
368+
*mddat = pb.hFileInfo.ioFlMdDat;
369+
*bkdat = pb.hFileInfo.ioFlBkDat;
370+
return 0;
371+
}
372+
373+
static OSErr
374+
PyMac_SetFileDates(fss, crdat, mddat, bkdat)
375+
FSSpec *fss;
376+
unsigned long crdat, mddat, bkdat;
377+
{
378+
CInfoPBRec pb;
379+
OSErr error;
380+
381+
pb.dirInfo.ioNamePtr = fss->name;
382+
pb.dirInfo.ioFDirIndex = 0;
383+
pb.dirInfo.ioVRefNum = fss->vRefNum;
384+
pb.dirInfo.ioDrDirID = fss->parID;
385+
error = PBGetCatInfoSync(&pb);
386+
if ( error ) return error;
387+
pb.dirInfo.ioNamePtr = fss->name;
388+
pb.dirInfo.ioFDirIndex = 0;
389+
pb.dirInfo.ioVRefNum = fss->vRefNum;
390+
pb.dirInfo.ioDrDirID = fss->parID;
391+
pb.hFileInfo.ioFlCrDat = crdat;
392+
pb.hFileInfo.ioFlMdDat = mddat;
393+
pb.hFileInfo.ioFlBkDat = bkdat;
394+
error = PBSetCatInfoSync(&pb);
395+
return error;
396+
}
397+
350398
static object *
351399
mfss_as_pathname(self, args)
352400
mfssobject *self;
@@ -507,6 +555,44 @@ mfss_SetFInfo(self, args)
507555
return None;
508556
}
509557

558+
static object *
559+
mfss_GetDates(self, args)
560+
mfssobject *self;
561+
object *args;
562+
{
563+
OSErr err;
564+
unsigned long crdat, mddat, bkdat;
565+
566+
if (!newgetargs(args, ""))
567+
return NULL;
568+
err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
569+
if ( err ) {
570+
PyErr_Mac(ErrorObject, err);
571+
return NULL;
572+
}
573+
return mkvalue("ddd", (double)crdat, (double)mddat, (double)bkdat);
574+
}
575+
576+
static object *
577+
mfss_SetDates(self, args)
578+
mfssobject *self;
579+
object *args;
580+
{
581+
OSErr err;
582+
double crdat, mddat, bkdat;
583+
584+
if (!newgetargs(args, "ddd", &crdat, &mddat, &bkdat))
585+
return NULL;
586+
err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
587+
(unsigned long)mddat, (unsigned long)bkdat);
588+
if ( err ) {
589+
PyErr_Mac(ErrorObject, err);
590+
return NULL;
591+
}
592+
INCREF(None);
593+
return None;
594+
}
595+
510596
static struct methodlist mfss_methods[] = {
511597
{"as_pathname", (method)mfss_as_pathname, 1},
512598
{"as_tuple", (method)mfss_as_tuple, 1},
@@ -516,6 +602,8 @@ static struct methodlist mfss_methods[] = {
516602
{"SetCreatorType", (method)mfss_SetCreatorType, 1},
517603
{"GetFInfo", (method)mfss_GetFInfo, 1},
518604
{"SetFInfo", (method)mfss_SetFInfo, 1},
605+
{"GetDates", (method)mfss_GetDates, 1},
606+
{"SetDates", (method)mfss_SetDates, 1},
519607

520608
{NULL, NULL} /* sentinel */
521609
};

0 commit comments

Comments
 (0)