ObjFW  Diff

Differences From Artifact [3d6aca4aa4]:

To Artifact [b6ef19d4e0]:


38
39
40
41
42
43
44

45
46
47
48
49
50
51
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52







+







#import "OFFileURLHandler.h"
#import "OFArray.h"
#import "OFDate.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OFSystemInfo.h"
#import "OFURL.h"

#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif

#import "OFCreateDirectoryFailedException.h"
146
147
148
149
150
151
152

153

154
155








156
157
158
159
160
161
162
163
164
165




166
167
168
169
170
171
172
147
148
149
150
151
152
153
154
155
156


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185







+

+
-
-
+
+
+
+
+
+
+
+










+
+
+
+







#endif

static int
of_stat(OFString *path, of_stat_t *buffer)
{
#if defined(OF_WINDOWS)
	WIN32_FILE_ATTRIBUTE_DATA data;
	bool success;

	if ([OFSystemInfo isWindowsNT])
	if (!GetFileAttributesExW(path.UTF16String, GetFileExInfoStandard,
	    &data)) {
		success = GetFileAttributesExW(path.UTF16String,
		    GetFileExInfoStandard, &data);
	else
		success = GetFileAttributesExA(
		    [path cStringWithEncoding: [OFLocale encoding]],
		    GetFileExInfoStandard, &data);

	if (!success) {
		setErrno();
		return -1;
	}

	buffer->st_size = (uint64_t)data.nFileSizeHigh << 32 |
	    data.nFileSizeLow;

	if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		buffer->st_mode = S_IFDIR;
	else if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
		/*
		 * No need to use A functions in this branch: This is only
		 * available on NTFS (and hence Windows NT) anyway.
		 */
		WIN32_FIND_DATAW findData;
		HANDLE findHandle;

		if ((findHandle = FindFirstFileW(path.UTF16String,
		    &findData)) == INVALID_HANDLE_VALUE) {
			setErrno();
			return -1;
588
589
590
591
592
593
594

595
596
597
598




599
600




601
602
603
604
605
606
607
601
602
603
604
605
606
607
608
609



610
611
612
613

614
615
616
617
618
619
620
621
622
623
624
625







+

-
-
-
+
+
+
+
-

+
+
+
+







- (void)of_setPOSIXPermissions: (OFNumber *)permissions
		   ofItemAtURL: (OFURL *)URL
		    attributes: (of_file_attributes_t)attributes
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	uint16_t mode = permissions.uInt16Value & 0777;
	OFString *path = URL.fileSystemRepresentation;
	int status;

# ifndef OF_WINDOWS
	if (chmod([path cStringWithEncoding: [OFLocale encoding]], mode) != 0)
# else
# ifdef OF_WINDOWS
	if ([OFSystemInfo isWindowsNT])
		status = _wchmod(path.UTF16String, mode);
	else
	if (_wchmod(path.UTF16String, mode) != 0)
# endif
		status = chmod(
		    [path cStringWithEncoding: [OFLocale encoding]], mode);

	if (status != 0)
		@throw [OFSetItemAttributesFailedException
		    exceptionWithURL: URL
			  attributes: attributes
		     failedAttribute: of_file_attribute_key_posix_permissions
			       errNo: errno];
#else
	OF_UNRECOGNIZED_SELECTOR
776
777
778
779
780
781
782



783






784
785
786
787
788
789
790
794
795
796
797
798
799
800
801
802
803

804
805
806
807
808
809
810
811
812
813
814
815
816







+
+
+
-
+
+
+
+
+
+








	if (![URL.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	path = URL.fileSystemRepresentation;

#if defined(OF_WINDOWS)
	int status;

	if ([OFSystemInfo isWindowsNT])
	if (_wmkdir(path.UTF16String) != 0)
		status = _wmkdir(path.UTF16String);
	else
		status = _mkdir(
		    [path cStringWithEncoding: [OFLocale encoding]]);

	if (status != 0)
		@throw [OFCreateDirectoryFailedException
		    exceptionWithURL: URL
			       errNo: errno];
#elif defined(OF_AMIGAOS)
	BPTR lock;

	if ((lock = CreateDir(
842
843
844
845
846
847
848
849
850
851
852



853
854
855



856
857
858


859
860
861
862
863





864
865
866
867



868
869
870
871



872
873
874
875
876
877
878
879
880








881
882
883
884
885
886
887




















































888
889
890
891
892
893
894
868
869
870
871
872
873
874

875
876
877
878
879
880



881
882
883
884


885
886
887




888
889
890
891
892
893



894
895
896
897



898
899
900
901








902
903
904
905
906
907
908
909
910






911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969







-



+
+
+
-
-
-
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	if (![URL.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	path = URL.fileSystemRepresentation;

#if defined(OF_WINDOWS)
	HANDLE handle;
	WIN32_FIND_DATAW fd;

	path = [path stringByAppendingString: @"\\*"];

	if ([OFSystemInfo isWindowsNT]) {
		WIN32_FIND_DATAW fd;

	if ((handle = FindFirstFileW(path.UTF16String,
	    &fd)) == INVALID_HANDLE_VALUE) {
		int errNo = 0;
		if ((handle = FindFirstFileW(path.UTF16String,
		    &fd)) == INVALID_HANDLE_VALUE) {
			int errNo = 0;

		if (GetLastError() == ERROR_FILE_NOT_FOUND)
			errNo = ENOENT;
			if (GetLastError() == ERROR_FILE_NOT_FOUND)
				errNo = ENOENT;

		@throw [OFOpenItemFailedException exceptionWithURL: URL
							      mode: nil
							     errNo: errNo];
	}
			@throw [OFOpenItemFailedException
			    exceptionWithURL: URL
					mode: nil
				       errNo: errNo];
		}

	@try {
		do {
			OFString *file;
		@try {
			do {
				OFString *file;

			if (!wcscmp(fd.cFileName, L".") ||
			    !wcscmp(fd.cFileName, L".."))
				continue;
				if (wcscmp(fd.cFileName, L".") == 0 ||
				    wcscmp(fd.cFileName, L"..") == 0)
					continue;

			file = [[OFString alloc]
			    initWithUTF16String: fd.cFileName];
			@try {
				[files addObject: file];
			} @finally {
				[file release];
			}
		} while (FindNextFileW(handle, &fd));
				file = [[OFString alloc]
				    initWithUTF16String: fd.cFileName];
				@try {
					[files addObject: file];
				} @finally {
					[file release];
				}
			} while (FindNextFileW(handle, &fd));

		if (GetLastError() != ERROR_NO_MORE_FILES)
			@throw [OFReadFailedException exceptionWithObject: self
							  requestedLength: 0
								    errNo: EIO];
	} @finally {
		FindClose(handle);
			if (GetLastError() != ERROR_NO_MORE_FILES)
				@throw [OFReadFailedException
				    exceptionWithObject: self
					requestedLength: 0
						  errNo: EIO];
		} @finally {
			FindClose(handle);
		}
	} else {
		of_string_encoding_t encoding = [OFLocale encoding];
		WIN32_FIND_DATA fd;

		if ((handle = FindFirstFileA(
		    [path cStringWithEncoding: encoding], &fd)) ==
		    INVALID_HANDLE_VALUE) {
			int errNo = 0;

			if (GetLastError() == ERROR_FILE_NOT_FOUND)
				errNo = ENOENT;

			@throw [OFOpenItemFailedException
			    exceptionWithURL: URL
					mode: nil
				       errNo: errNo];
		}

		@try {
			do {
				OFString *file;

				if (strcmp(fd.cFileName, ".") == 0 ||
				    strcmp(fd.cFileName, "..") == 0)
					continue;

				file = [[OFString alloc]
				    initWithCString: fd.cFileName
					   encoding: encoding];
				@try {
					[files addObject: file];
				} @finally {
					[file release];
				}
			} while (FindNextFileA(handle, &fd));

			if (GetLastError() != ERROR_NO_MORE_FILES)
				@throw [OFReadFailedException
				    exceptionWithObject: self
					requestedLength: 0
						  errNo: EIO];
		} @finally {
			FindClose(handle);
		}
	}
#elif defined(OF_AMIGAOS)
	of_string_encoding_t encoding = [OFLocale encoding];
	BPTR lock;

	if ((lock = Lock([path cStringWithEncoding: encoding],
	    SHARED_LOCK)) == 0) {
1090
1091
1092
1093
1094
1095
1096


1097
1098
1099




1100
1101




1102
1103
1104
1105


1106
1107
1108
1109




1110
1111




1112
1113
1114
1115
1116
1117
1118
1165
1166
1167
1168
1169
1170
1171
1172
1173



1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188




1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204







+
+
-
-
-
+
+
+
+
-

+
+
+
+




+
+
-
-
-
-
+
+
+
+
-

+
+
+
+







			[self removeItemAtURL: [OFURL fileURLWithPath:
			    [path stringByAppendingPathComponent: item]]];

			objc_autoreleasePoolPop(pool2);
		}

#ifndef OF_AMIGAOS
		int status;

# ifndef OF_WINDOWS
		if (rmdir([path cStringWithEncoding: [OFLocale encoding]]) != 0)
# else
# ifdef OF_WINDOWS
		if ([OFSystemInfo isWindowsNT])
			status = _wrmdir(path.UTF16String);
		else
		if (_wrmdir(path.UTF16String) != 0)
# endif
			status = rmdir(
			    [path cStringWithEncoding: [OFLocale encoding]]);

		if (status != 0)
			@throw [OFRemoveItemFailedException
				exceptionWithURL: URL
					   errNo: errno];
	} else {
		int status;

# ifndef OF_WINDOWS
		if (unlink([path cStringWithEncoding:
		    [OFLocale encoding]]) != 0)
# else
# ifdef OF_WINDOWS
		if ([OFSystemInfo isWindowsNT])
			status = _wunlink(path.UTF16String);
		else
		if (_wunlink(path.UTF16String) != 0)
# endif
			status = unlink(
			    [path cStringWithEncoding: [OFLocale encoding]]);

		if (status != 0)
			@throw [OFRemoveItemFailedException
			    exceptionWithURL: URL
				       errNo: errno];
#endif
	}

#ifdef OF_AMIGAOS
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263
1328
1329
1330
1331
1332
1333
1334








1335
1336
1337
1338
1339
1340
1341
1342







-
-
-
-
-
-
-
-
+







		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
				     errNo: EEXIST];

	pool = objc_autoreleasePoolPush();

#if defined(OF_WINDOWS)
	if (_wrename(source.fileSystemRepresentation.UTF16String,
	    destination.fileSystemRepresentation.UTF16String) != 0)
		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
				     errNo: errno];
#elif defined(OF_AMIGAOS)
#ifdef OF_AMIGAOS
	of_string_encoding_t encoding = [OFLocale encoding];

	if (!Rename([source.fileSystemRepresentation
	    cStringWithEncoding: encoding],
	    [destination.fileSystemRepresentation
	    cStringWithEncoding: encoding])) {
		int errNo;
1286
1287
1288
1289
1290
1291
1292








1293

1294
1295
1296
1297
1298









1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379

1380
1381




1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401







+
+
+
+
+
+
+
+
-
+

-
-
-
-
+
+
+
+
+
+
+
+
+












		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
				     errNo: errNo];
	}
#else
	int status;

# ifdef OF_WINDOWS
	if ([OFSystemInfo isWindowsNT])
		status = _wrename(source.fileSystemRepresentation.UTF16String,
		    destination.fileSystemRepresentation.UTF16String);
	else {
# endif
	of_string_encoding_t encoding = [OFLocale encoding];
		of_string_encoding_t encoding = [OFLocale encoding];

	if (rename([source.fileSystemRepresentation
	    cStringWithEncoding: encoding],
	    [destination.fileSystemRepresentation
	    cStringWithEncoding: encoding]) != 0)
		status = rename([source.fileSystemRepresentation
		    cStringWithEncoding: encoding],
		    [destination.fileSystemRepresentation
		    cStringWithEncoding: encoding]);
# ifdef OF_WINDOWS
	}
# endif

	if (status != 0)
		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
				     errNo: errno];
#endif

	objc_autoreleasePoolPop(pool);

	return true;
}
@end