discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Some trouble with NSFileManager on windows


From: Roland Schwingel
Subject: Some trouble with NSFileManager on windows
Date: Mon, 08 Mar 2010 11:41:14 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Hi...

On windows I got some trouble with the movePath: in NSFileManager if you move a file especially on a so called "VMWare Shared Folder". I tracked it down to the fact that on windows GNUstep is currently not able to get the fileSystemNumber. It is simply not implemented. Furthermore if you call fileSystemAttributesAtPath: on a file on windows this call fails always (independant of the "VMWare Shared Folder"). So the movePath: method of NSFileManager optimizes wrong here.

The attached (mostly trivial) patch adds an implementation for the missing fileSystemNumber thing and also fixes the fileSystemAttributesAtPath: thing.

Thanks for applying,

Roland

--- NSFileManager.m.orig        2010-03-03 12:05:30.000000000 +0100
+++ NSFileManager.m     2010-03-08 10:39:12.000000000 +0100
@@ -192,7 +192,7 @@
 #define        _CLOSEDIR(A)    _wclosedir(A)
 #define        _OPENDIR(A)     _wopendir(A)
 #define        _READDIR(A)     _wreaddir(A)
-#define        _RENAME(A,B)    _wrename(A,B)
+#define        _RENAME(A,B)    
(MoveFileExW(A,B,MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH)==0)?-1:0
 #define        _RMDIR(A)       _wrmdir(A)
 #define        _STAT(A,B)      _wstat(A,B)
 #define        _UTIME(A,B)     _wutime(A,B)
@@ -1778,9 +1778,18 @@
   };
   DWORD SectorsPerCluster, BytesPerSector, NumberFreeClusters;
   DWORD TotalNumberClusters;
+  DWORD volumeSerialNumber = 0;
   const _CHAR *lpath = [self fileSystemRepresentationWithPath: path];
 
-  if (!GetDiskFreeSpaceW(lpath, &SectorsPerCluster,
+  _CHAR volumePathName[128];
+  if (!GetVolumePathNameW(lpath,volumePathName,128))
+  {
+    return nil;
+  }
+
+  
GetVolumeInformationW(volumePathName,NULL,0,&volumeSerialNumber,NULL,NULL,NULL,0);
+
+  if (!GetDiskFreeSpaceW(volumePathName,&SectorsPerCluster,
     &BytesPerSector, &NumberFreeClusters, &TotalNumberClusters))
     {
       return nil;
@@ -1797,7 +1806,7 @@
   values[1] = [NSNumber numberWithUnsignedLongLong: freesize];
   values[2] = [NSNumber numberWithLong: LONG_MAX];
   values[3] = [NSNumber numberWithLong: LONG_MAX];
-  values[4] = [NSNumber numberWithUnsignedInt: 0];
+  values[4] = [NSNumber numberWithUnsignedInt: volumeSerialNumber];
 
   return [NSDictionary dictionaryWithObjects: values forKeys: keys count: 5];
 
@@ -3227,7 +3236,18 @@
 
 - (NSUInteger) fileSystemNumber
 {
+#if defined(__MINGW32__)
+  DWORD volumeSerialNumber = 0;
+  _CHAR volumePathName[128];
+  if (GetVolumePathNameW(_path,volumePathName,128))
+  {
+    
GetVolumeInformationW(volumePathName,NULL,0,&volumeSerialNumber,NULL,NULL,NULL,0);
+  }
+
+  return (NSUInteger)volumeSerialNumber;
+#else
   return statbuf.st_dev;
+#endif
 }
 
 - (NSString*) fileType

reply via email to

[Prev in Thread] Current Thread [Next in Thread]