Differences From Artifact [6f389e5f28]:
- File
src/OFFileManager.m
— part of check-in
[fc7f20ff34]
at
2017-01-16 02:23:54
on branch trunk
— OFFileManager: Use EINVAL instead of ENOTSUP
ENOTSUP is for sockets. (user: js, size: 25134) [annotate] [blame] [check-ins using]
To Artifact [f4973b705b]:
- File
src/OFFileManager.m
— part of check-in
[4af49a13c3]
at
2017-05-07 20:10:13
on branch trunk
— Small code style change
Casts are now written like types in variable declarations. (user: js, size: 25177) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
161 162 163 164 165 166 167 | (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD)) GetProcAddress(module, "CreateSymbolicLinkW"); #endif defaultManager = [[OFFileManager alloc] init]; } | | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD)) GetProcAddress(module, "CreateSymbolicLinkW"); #endif defaultManager = [[OFFileManager alloc] init]; } + (OFFileManager *)defaultManager { return defaultManager; } - (OFString *)currentDirectoryPath { OFString *ret; #ifndef OF_WINDOWS char *buffer = getcwd(NULL, 0); #else wchar_t *buffer = _wgetcwd(NULL, 0); #endif |
︙ | ︙ | |||
190 191 192 193 194 195 196 | } @finally { free(buffer); } return ret; } | | | | | | | | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | } @finally { free(buffer); } return ret; } - (bool)fileExistsAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) == -1) return false; if (S_ISREG(s.st_mode)) return true; return false; } - (bool)directoryExistsAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) == -1) return false; if (S_ISDIR(s.st_mode)) return true; return false; } #if defined(OF_HAVE_SYMLINK) - (bool)symbolicLinkExistsAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_lstat(path, &s) == -1) return false; if (S_ISLNK(s.st_mode)) return true; return false; } #elif defined(OF_WINDOWS) - (bool)symbolicLinkExistsAtPath: (OFString *)path { WIN32_FIND_DATAW data; if (!FindFirstFileW([path UTF16String], &data)) return false; if ((data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && data.dwReserved0 == IO_REPARSE_TAG_SYMLINK) return true; return false; } #endif - (void)createDirectoryAtPath: (OFString *)path { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef OF_WINDOWS if (mkdir([path cStringWithEncoding: [OFLocalization encoding]], DIR_MODE) != 0) #else if (_wmkdir([path UTF16String]) != 0) #endif @throw [OFCreateDirectoryFailedException exceptionWithPath: path errNo: errno]; } - (void)createDirectoryAtPath: (OFString *)path createParents: (bool)createParents { OFString *currentPath = nil; if (!createParents) { [self createDirectoryAtPath: path]; return; |
︙ | ︙ | |||
304 305 306 307 308 309 310 | objc_autoreleasePoolPop(pool); [currentPath autorelease]; } } | | | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | objc_autoreleasePoolPop(pool); [currentPath autorelease]; } } - (OFArray *)contentsOfDirectoryAtPath: (OFString *)path { OFMutableArray *files; #ifndef OF_WINDOWS of_string_encoding_t encoding; #endif if (path == nil) |
︙ | ︙ | |||
424 425 426 427 428 429 430 | #endif [files makeImmutable]; return files; } | | | | | | | | | | | | 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | #endif [files makeImmutable]; return files; } - (void)changeCurrentDirectoryPath: (OFString *)path { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef OF_WINDOWS if (chdir([path cStringWithEncoding: [OFLocalization encoding]]) != 0) #else if (_wchdir([path UTF16String]) != 0) #endif @throw [OFChangeCurrentDirectoryPathFailedException exceptionWithPath: path errNo: errno]; } - (of_offset_t)sizeOfFileAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; return s.st_size; } - (OFDate *)accessTimeOfItemAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_atime]; } - (OFDate *)modificationTimeOfItemAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_mtime]; } - (OFDate *)statusChangeTimeOfItemAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_ctime]; } #ifdef OF_HAVE_CHMOD - (mode_t)permissionsOfItemAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; return s.st_mode; } - (void)changePermissionsOfItemAtPath: (OFString *)path permissions: (mode_t)permissions { if (path == nil) @throw [OFInvalidArgumentException exception]; # ifndef OF_WINDOWS if (chmod([path cStringWithEncoding: [OFLocalization encoding]], permissions) != 0) # else if (_wchmod([path UTF16String], permissions) != 0) # endif @throw [OFChangePermissionsFailedException exceptionWithPath: path permissions: permissions errNo: errno]; } #endif #ifdef OF_HAVE_CHOWN - (void)getOwner: (OFString **)owner group: (OFString **)group ofItemAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) |
︙ | ︙ | |||
572 573 574 575 576 577 578 | # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } #endif } | | | | | 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } #endif } - (void)changeOwnerOfItemAtPath: (OFString *)path owner: (OFString *)owner group: (OFString *)group { uid_t uid = -1; gid_t gid = -1; of_string_encoding_t encoding; if (path == nil || (owner == nil && group == nil)) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
630 631 632 633 634 635 636 | @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group errNo: errno]; } #endif | | | | 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group errNo: errno]; } #endif - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool; of_stat_t s; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
774 775 776 777 778 779 780 | exceptionWithSourcePath: source destinationPath: destination errNo: EINVAL]; objc_autoreleasePoolPop(pool); } | | | | 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | exceptionWithSourcePath: source destinationPath: destination errNo: EINVAL]; objc_autoreleasePoolPop(pool); } - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool; of_stat_t s; #ifndef OF_WINDOWS of_string_encoding_t encoding; #endif |
︙ | ︙ | |||
833 834 835 836 837 838 839 | errNo: [e errNo]]; } } objc_autoreleasePoolPop(pool); } | | | 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | errNo: [e errNo]]; } } objc_autoreleasePoolPop(pool); } - (void)removeItemAtPath: (OFString *)path { void *pool; of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
902 903 904 905 906 907 908 | errNo: errno]; } objc_autoreleasePoolPop(pool); } #if defined(OF_HAVE_LINK) | | | | | | | | | | 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 970 971 972 973 974 975 976 977 978 979 980 981 982 | errNo: errno]; } objc_autoreleasePoolPop(pool); } #if defined(OF_HAVE_LINK) - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool; of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); encoding = [OFLocalization encoding]; if (link([source cStringWithEncoding: encoding], [destination cStringWithEncoding: encoding]) != 0) @throw [OFLinkFailedException exceptionWithSourcePath: source destinationPath: destination errNo: errno]; objc_autoreleasePoolPop(pool); } #else - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if (!CreateHardLinkW([destination UTF16String], [source UTF16String], NULL)) @throw [OFLinkFailedException exceptionWithSourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); } #endif #if defined(OF_HAVE_SYMLINK) - (void)createSymbolicLinkAtPath: (OFString *)destination withDestinationPath: (OFString *)source { void *pool; of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); encoding = [OFLocalization encoding]; if (symlink([source cStringWithEncoding: encoding], [destination cStringWithEncoding: encoding]) != 0) @throw [OFCreateSymbolicLinkFailedException exceptionWithSourcePath: source destinationPath: destination errNo: errno]; objc_autoreleasePoolPop(pool); } #elif defined(OF_WINDOWS) - (void)createSymbolicLinkAtPath: (OFString *)destination withDestinationPath: (OFString *)source { void *pool; if (func_CreateSymbolicLinkW == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; |
︙ | ︙ | |||
992 993 994 995 996 997 998 | destinationPath: destination]; objc_autoreleasePoolPop(pool); } #endif #ifdef OF_HAVE_READLINK | | | 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | destinationPath: destination]; objc_autoreleasePoolPop(pool); } #endif #ifdef OF_HAVE_READLINK - (OFString *)destinationOfSymbolicLinkAtPath: (OFString *)path { char destination[PATH_MAX]; ssize_t length; of_string_encoding_t encoding; if (path == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
1014 1015 1016 1017 1018 1019 1020 | errNo: errno]; return [OFString stringWithCString: destination encoding: encoding length: length]; } #elif defined(OF_WINDOWS) | | | 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 | errNo: errno]; return [OFString stringWithCString: destination encoding: encoding length: length]; } #elif defined(OF_WINDOWS) - (OFString *)destinationOfSymbolicLinkAtPath: (OFString *)path { HANDLE handle; /* Check if we're on a version that actually supports symlinks. */ if (func_CreateSymbolicLinkW == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; |
︙ | ︙ |