ObjFW  Diff

Differences From Artifact [f54ca9d551]:

To Artifact [bad8975ada]:

  • File src/OFURLHandler_file.m — part of check-in [e6e027971e] at 2019-04-10 21:22:34 on branch trunk — Use GetFileAttributesW() to see if a file exists

    _wstat64() does not work on drives, so e.g. for C:\ it would always
    return that it doesn't exist.

    Ideally, in the future, all calls to _wstat64() would be replaced with
    native calls that return the same information, to avoid any
    inconsistencies. At that point, the Amiga re-implementation of of_stat()
    could be deprecated as well. (user: js, size: 31158) [annotate] [blame] [check-ins using]


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




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

	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];





	if (of_stat(URL.fileSystemRepresentation, &s) == -1)

		return false;


	ret = S_ISREG(s.st_mode);


	objc_autoreleasePoolPop(pool);

	return ret;
}

- (bool)directoryExistsAtURL: (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];











	if (of_stat(URL.fileSystemRepresentation, &s) == -1)

		return false;


	ret = S_ISDIR(s.st_mode);


	objc_autoreleasePoolPop(pool);

	return ret;
}

- (void)createDirectoryAtURL: (OFURL *)URL







>

>








>
>
>
>
|
>

|
>

>









>
>
>

>








>
>
>
>
>
>
>
>
>
>
|
>

|
>

>







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