Skip to content

Commit

Permalink
21379 FileAttributesPlugin _WIN32 & nil creationTime
Browse files Browse the repository at this point in the history
Name: FileAttributesPlugin.oscog-AlistairGrant.28
Author: AlistairGrant
Time: 21 February 2018, 9:46:27.211606 am
UUID: fb804aff-1cbd-4ffa-b48a-e3d665d10673
Ancestors: FileAttributesPlugin.oscog-AlistairGrant.27

1.2.6: Clean up Windows specific code, return nil for creationTime on
Unix

- Use the option: pragma to make Windows specific methods only compile
  on Windows.
- Return nil instead of -1 for file creationTime on Unix

Fogbugz:
https://pharo.fogbugz.com/f/cases/21379/FileAttributesPlugin-_WIN32-nil-creationTime
  • Loading branch information
akgrant committed Feb 21, 2018
1 parent b2efb7d commit 74f805c
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions src/plugins/FileAttributesPlugin/FileAttributesPlugin.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.2329 uuid: 74077530-8ed4-4601-a446-062057eeb3d3
VMPluginCodeGenerator VMMaker.oscog-eem.2335 uuid: 9525a938-a6aa-43d4-8bdc-e844e8e7e360
from
FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.26 uuid: 07c4e352-8193-452a-a80a-440f0811d43f
FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.28 uuid: fb804aff-1cbd-4ffa-b48a-e3d665d10673
*/
static char __buildInfo[] = "FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.26 uuid: 07c4e352-8193-452a-a80a-440f0811d43f " __DATE__ ;
static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.28 uuid: fb804aff-1cbd-4ffa-b48a-e3d665d10673 " __DATE__ ;



Expand Down Expand Up @@ -65,12 +65,16 @@ static sqInt byteArrayFromCStringto(const char *aCString, sqInt *byteArrayOop);
static sqInt canOpenDirectoryStreamForlength(char *aPathCString, sqInt length);
static sqInt canStatFilePathlength(char *aPathCString, sqInt length);
EXPORT(sqInt) checkAccessmodeto(sqInt pathString, sqInt mode, sqInt *flag);
#if _WIN32
static sqInt fileCreationTimeForlengthto(char *pathString, sqInt pathLength, time_t *creationDate);
#endif /* _WIN32 */
static int fileToAttributeArraymaskarray(char *cPathName, sqInt attributeMask, sqInt *attributeArray);
EXPORT(const char*) getModuleName(void);
EXPORT(sqInt) initialiseModule(void);
static sqInt isSymlinkboolean(char *cPathName, sqInt *resultOop);
#if _WIN32
static sqInt offsetStatBufTimesForWIN32(struct stat *statBufPointer);
#endif /* _WIN32 */
static sqInt oopFromTimeT(time_t posixSeconds);
static int openDirectoryStreamptr(sqInt pathOOP, osdir **osdirPtr);
static int pathOoptoBuffermaxLen(sqInt pathNameOop, char *cPathName, sqInt maxLen);
Expand Down Expand Up @@ -160,9 +164,9 @@ extern
struct VirtualMachine* interpreterProxy;
static const char *moduleName =
#ifdef SQUEAK_BUILTIN_PLUGIN
"FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.26 (i)"
"FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.28 (i)"
#else
"FileAttributesPlugin * FileAttributesPlugin.oscog-AlistairGrant.26 (e)"
"FileAttributesPlugin FileAttributesPlugin.oscog-AlistairGrant.28 (e)"
#endif
;
static void * sCLPfn;
Expand Down Expand Up @@ -348,43 +352,37 @@ checkAccessmodeto(sqInt pathString, sqInt mode, sqInt *flag)
*/

/* FileAttributesPlugin>>#fileCreationTimeFor:length:to: */
#if _WIN32
static sqInt
fileCreationTimeForlengthto(char *pathString, sqInt pathLength, time_t *creationDate)
{
SYSTEMTIME sysTime;
struct tm tm;
WCHAR *win32Path;
WIN32_FILE_ATTRIBUTE_DATA winAttrs;


#ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA winAttrs;
WCHAR *win32Path;
SYSTEMTIME sysTime;
#endif

memset(&tm, 0, sizeof(tm));

#ifdef _WIN32
/* convert the supplied path name into a wide string */
ALLOC_WIN32_PATH(win32Path, pathString, pathLength);
win32Path = 0;
memset((&tm), 0, sizeof(tm));
ALLOC_WIN32_PATH(win32Path, pathString, pathLength);
if ((GetFileAttributesExW(win32Path, 0, &winAttrs)) == 0) {
return -4 /* getAttributesFailed */;
}
if ((FileTimeToSystemTime(&winAttrs.ftCreationTime, &sysTime)) == 0) {
return -5 /* timeConversionFailed */;
}

tm.tm_year = sysTime.wYear - 1900;
tm.tm_mon = sysTime.wMonth - 1;
tm.tm_mday = sysTime.wDay;

tm.tm_hour = sysTime.wHour;
tm.tm_min = sysTime.wMinute;
tm.tm_sec = sysTime.wSecond;
tm.tm_isdst = 0;
#endif

*creationDate = mktime(&tm);
tm.tm_year = sysTime.wYear - 1900;
tm.tm_mon = sysTime.wMonth - 1;
tm.tm_mday = sysTime.wDay;

tm.tm_hour = sysTime.wHour;
tm.tm_min = sysTime.wMinute;
tm.tm_sec = sysTime.wSecond;
tm.tm_isdst = 0;
*creationDate = mktime(&tm);
return 0;
}
#endif /* _WIN32 */


/* Answer a file attribute array from pathNameOop. */
Expand Down Expand Up @@ -625,34 +623,30 @@ isSymlinkboolean(char *cPathName, sqInt *resultOop)

/* Adjust the statBuffer to UTC, see
https://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx
*/
/* Until <option: _WIN32> is available, leave the entire method wrapped in
cCode:
*/

/* FileAttributesPlugin>>#offsetStatBufTimesForWIN32: */
#if _WIN32
static sqInt
offsetStatBufTimesForWIN32(struct stat *statBufPointer)
{
TIME_ZONE_INFORMATION dtzi;
long offset;
sqInt status;

offset = 0;
status = 0;

#ifdef _WIN32
TIME_ZONE_INFORMATION dtzi;

status = GetTimeZoneInformation(&dtzi);
offset = dtzi.Bias * 60;
/* Adjust for DST if required */
if (status == 2) { offset -= 3600; }
statBufPointer->st_atime += offset;
statBufPointer->st_mtime += offset;
statBufPointer->st_ctime += offset;
#endif;
status = GetTimeZoneInformation((&dtzi));

/* Adjust for DST if required */
offset = (dtzi.Bias) * 60;
if (status == 2) {
offset -= 3600;
}
statBufPointer->st_atime += offset;
statBufPointer->st_mtime += offset;
statBufPointer->st_ctime += offset;
return 0;
}
#endif /* _WIN32 */


/* Answer an object representation of the provided time (time_t).
Expand Down Expand Up @@ -934,6 +928,8 @@ primitiveFileAttribute(void)
}
else {
if (attributeNumber == 12) {

# if defined(_WIN32)
status = fileCreationTimeForlengthto(cPathName, strlen(cPathName), (&creationDate));
if (status != 0) {
return primitiveFailForOSError(status);
Expand All @@ -942,6 +938,9 @@ primitiveFileAttribute(void)
resultOop = ((sizeof(time_t)) == 4
? signed32BitIntegerFor(creationDate)
: signed64BitIntegerFor(creationDate));
# else /* defined(_WIN32) */
resultOop = nilObject();
# endif /* defined(_WIN32) */
}
else {
if (attributeNumber < 16) {
Expand Down Expand Up @@ -1301,7 +1300,7 @@ primitiveRewinddir(void)
EXPORT(sqInt)
primitiveVersionString(void)
{
popthenPush(1, stringFromCString("1.2.5"));
popthenPush(1, stringFromCString("1.2.6"));
return 0;
}

Expand Down

0 comments on commit 74f805c

Please sign in to comment.