Overview
Comment: | Use GetFileAttributesW() to see if a file exists
_wstat64() does not work on drives, so e.g. for C:\ it would always Ideally, in the future, all calls to _wstat64() would be replaced with |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
e6e027971e2c171fb7a43f5b291a8f27 |
User & Date: | js on 2019-04-10 21:22:34 |
Other Links: | manifest | tags |
Context
2019-04-11
| ||
00:34 | Make OFFileManager available with --disable-files check-in: c52f38388c user: js tags: trunk | |
2019-04-10
| ||
21:22 | Use GetFileAttributesW() to see if a file exists check-in: e6e027971e user: js tags: trunk | |
2019-04-08
| ||
18:19 | configure: Add a hack on DJGPP to find some tools check-in: 934dab8faf user: js tags: trunk | |
Changes
Modified src/OFURLHandler_file.m from [f54ca9d551] to [bad8975ada].
︙ | ︙ | |||
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | * On some systems, this is needed to initialize the file system driver. */ [OFFile class]; } + (bool)of_directoryExistsAtPath: (OFString *)path { of_stat_t s; if (of_stat(path, &s) == -1) return false; return S_ISDIR(s.st_mode); } - (OFStream *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFFile *file = [[OFFile alloc] | > > > > > > > > | 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 | * On some systems, this is needed to initialize the file system driver. */ [OFFile class]; } + (bool)of_directoryExistsAtPath: (OFString *)path { #ifdef OF_WINDOWS DWORD attributes = GetFileAttributesW(path.UTF16String); if (attributes == INVALID_FILE_ATTRIBUTES) return false; return (attributes & FILE_ATTRIBUTE_DIRECTORY); #else of_stat_t s; if (of_stat(path, &s) == -1) return false; return S_ISDIR(s.st_mode); #endif } - (OFStream *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFFile *file = [[OFFile alloc] |
︙ | ︙ | |||
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | objc_autoreleasePoolPop(pool); } - (bool)fileExistsAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); of_stat_t s; bool ret; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; | > > > > > > | > | > > > > > > > > > > > > > > > > | > | > > | 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | objc_autoreleasePoolPop(pool); } - (bool)fileExistsAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); #ifndef OF_WINDOWS of_stat_t s; #endif bool ret; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; #ifdef OF_WINDOWS ret = (GetFileAttributesW(URL.fileSystemRepresentation.UTF16String) != INVALID_FILE_ATTRIBUTES); #else if (of_stat(URL.fileSystemRepresentation, &s) == -1) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISREG(s.st_mode); #endif objc_autoreleasePoolPop(pool); return ret; } - (bool)directoryExistsAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); #ifdef OF_WINDOWS DWORD attributes; #else of_stat_t s; #endif bool ret; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; #ifdef OF_WINDOWS attributes = GetFileAttributesW( URL.fileSystemRepresentation.UTF16String); if (attributes == INVALID_FILE_ATTRIBUTES) { objc_autoreleasePoolPop(pool); return false; } ret = (attributes & FILE_ATTRIBUTE_DIRECTORY); #else if (of_stat(URL.fileSystemRepresentation, &s) == -1) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISDIR(s.st_mode); #endif objc_autoreleasePoolPop(pool); return ret; } - (void)createDirectoryAtURL: (OFURL *)URL |
︙ | ︙ |