ObjFW  Diff

Differences From Artifact [b686c0a44c]:

To Artifact [9c28a1ea8f]:


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef S_IRGRP
# define S_IRGRP 0
#endif
#ifndef S_IROTH
# define S_IROTH 0
#endif

#define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH

#ifndef _WIN32
# define PATH_DELIM '/'
#else
# define PATH_DELIM '\\'
#endif







|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef S_IRGRP
# define S_IRGRP 0
#endif
#ifndef S_IROTH
# define S_IROTH 0
#endif

#define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH

#ifndef _WIN32
# define PATH_DELIM '/'
#else
# define PATH_DELIM '\\'
#endif
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
	}

	/*
	 * Only one component, but the trailing delimiter might have been
	 * removed, so return a new string anyway.
	 */
	if (i < 0)
		i++;

	return [OFString stringWithCString: path_c + i
				    length: path_len - i];
}

+ (BOOL)fileExistsAtPath: (OFString*)path
{







|







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
	}

	/*
	 * Only one component, but the trailing delimiter might have been
	 * removed, so return a new string anyway.
	 */
	if (i < 0)
		i = 0;

	return [OFString stringWithCString: path_c + i
				    length: path_len - i];
}

+ (BOOL)fileExistsAtPath: (OFString*)path
{
286
287
288
289
290
291
292














































293
294
295
296
297
298
299
	if (chown([path cString], owner, group))
		@throw [OFChangeFileOwnerFailedException newWithClass: self
								 path: path
								owner: owner
								group: group];
}
#endif















































+ (void)renameFileAtPath: (OFString*)from
		  toPath: (OFString*)to
{
#ifndef _WIN32
	if (rename([from cString], [to cString]))
#else







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
	if (chown([path cString], owner, group))
		@throw [OFChangeFileOwnerFailedException newWithClass: self
								 path: path
								owner: owner
								group: group];
}
#endif

+ (void)copyFileAtPath: (OFString*)from
		toPath: (OFString*)to
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	BOOL override;
	OFFile *src;
	OFFile *dest;
	char buf[4096];

	if ([self directoryExistsAtPath: to]) {
		OFString *filename = [self lastComponentOfPath: from];
		to = [OFString stringWithPath: to, filename, nil];
	}

	override = [self fileExistsAtPath: to];

	src = nil;
	dest = nil;

	@try {
		src = [OFFile fileWithPath: from
				      mode: @"rb"];
		dest = [OFFile fileWithPath: to
				       mode: @"wb"];

		while (![src atEndOfStream]) {
			size_t len = [src readNBytes: 4096
					  intoBuffer: buf];
			[dest writeNBytes: len
			       fromBuffer: buf];
		}

		if (!override) {
			struct stat s;

			if (fstat(src->fd, &s) == 0)
				fchmod(dest->fd, s.st_mode);
		}
	} @finally {
		[src close];
		[dest close];
	}

	[pool release];
}

+ (void)renameFileAtPath: (OFString*)from
		  toPath: (OFString*)to
{
#ifndef _WIN32
	if (rename([from cString], [to cString]))
#else
310
311
312
313
314
315
316







317
318
319
320
321
322
323
	if (unlink([path cString]))
#else
	if (!DeleteFile([path cString]))
#endif
		@throw [OFDeleteFileFailedException newWithClass: self
							    path: path];
}








#ifndef _WIN32
+ (void)linkFileAtPath: (OFString*)src
		toPath: (OFString*)dest
{
	if (link([src cString], [dest cString]) != 0)
		@throw [OFLinkFailedException newWithClass: self







>
>
>
>
>
>
>







356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
	if (unlink([path cString]))
#else
	if (!DeleteFile([path cString]))
#endif
		@throw [OFDeleteFileFailedException newWithClass: self
							    path: path];
}

+ (void)deleteDirectoryAtPath: (OFString*)path
{
	if (rmdir([path cString]))
		@throw [OFDeleteDirectoryFailedException newWithClass: self
								 path: path];
}

#ifndef _WIN32
+ (void)linkFileAtPath: (OFString*)src
		toPath: (OFString*)dest
{
	if (link([src cString], [dest cString]) != 0)
		@throw [OFLinkFailedException newWithClass: self