ObjFW  Diff

Differences From Artifact [737527b063]:

To Artifact [a3021efc2a]:


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
285

286
287
288
289
290
291
292
293
294
295
296
297
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
285
286
287
288







-
-
-
+
-









-
-
-
+
-
-
-
+













-
+



-
-







		    exceptionWithPath: path
				errNo: errno];
}

- (void)createDirectoryAtPath: (OFString*)path
		createParents: (bool)createParents
{
	void *pool;
	OFArray *pathComponents;
	OFString *currentPath = nil, *component;
	OFString *currentPath = nil;
	OFEnumerator *enumerator;

	if (!createParents) {
		[self createDirectoryAtPath: path];
		return;
	}

	if (path == nil)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();

	pathComponents = [path pathComponents];
	for (OFString *component in [path pathComponents]) {
	enumerator = [pathComponents objectEnumerator];
	while ((component = [enumerator nextObject]) != nil) {
		void *pool2 = objc_autoreleasePoolPush();
		void *pool = objc_autoreleasePoolPush();

		if (currentPath != nil)
			currentPath = [currentPath
			    stringByAppendingPathComponent: component];
		else
			currentPath = component;

		if ([currentPath length] > 0 &&
		    ![self directoryExistsAtPath: currentPath])
			[self createDirectoryAtPath: currentPath];

		[currentPath retain];

		objc_autoreleasePoolPop(pool2);
		objc_autoreleasePoolPop(pool);

		[currentPath autorelease];
	}

	objc_autoreleasePoolPop(pool);
}

- (OFArray*)contentsOfDirectoryAtPath: (OFString*)path
{
	OFMutableArray *files;
#ifndef OF_WINDOWS
	of_string_encoding_t encoding;
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
582
583
584
585
586
587
588


589
590
591
592
593
594
595







-
-







		@throw [OFCopyItemFailedException
		    exceptionWithSourcePath: source
			    destinationPath: destination
				      errNo: errno];

	if (S_ISDIR(s.st_mode)) {
		OFArray *contents;
		OFEnumerator *enumerator;
		OFString *item;

		@try {
			[self createDirectoryAtPath: destination];
#ifdef OF_HAVE_CHMOD
			[self changePermissionsOfItemAtPath: destination
						permissions: s.st_mode];
#endif
618
619
620
621
622
623
624
625

626
627
628
629
630
631
632
633
607
608
609
610
611
612
613

614

615
616
617
618
619
620
621







-
+
-







				    exceptionWithSourcePath: source
					    destinationPath: destination
						      errNo: [e errNo]];

			@throw e;
		}

		enumerator = [contents objectEnumerator];
		for (OFString *item in contents) {
		while ((item = [enumerator nextObject]) != nil) {
			void *pool2 = objc_autoreleasePoolPush();
			OFString *sourcePath, *destinationPath;

			sourcePath =
			    [source stringByAppendingPathComponent: item];
			destinationPath =
			    [destination stringByAppendingPathComponent: item];
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

817
818
819
820
821
822
823
824
776
777
778
779
780
781
782


783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801

802

803
804
805
806
807
808
809







-
-



















-
+
-








	if (of_lstat(path, &s) != 0)
		@throw [OFRemoveItemFailedException exceptionWithPath: path
								errNo: errno];

	if (S_ISDIR(s.st_mode)) {
		OFArray *contents;
		OFEnumerator *enumerator;
		OFString *item;

		@try {
			contents = [self contentsOfDirectoryAtPath: path];
		} @catch (id e) {
			/*
			 * Only convert exceptions to
			 * OFRemoveItemFailedException that have an errNo
			 * property. This covers all I/O related exceptions
			 * from the operations used to remove an item, all
			 * others should be left as is.
			 */
			if ([e respondsToSelector: @selector(errNo)])
				@throw [OFRemoveItemFailedException
				    exceptionWithPath: path
						errNo: [e errNo]];

			@throw e;
		}

		enumerator = [contents objectEnumerator];
		for (OFString *item in contents) {
		while ((item = [enumerator nextObject]) != nil) {
			void *pool2 = objc_autoreleasePoolPush();

			[self removeItemAtPath:
			    [path stringByAppendingPathComponent: item]];

			objc_autoreleasePoolPop(pool2);
		}