ObjFW  Diff

Differences From Artifact [6e1359d60a]:

To Artifact [b7dd938e02]:


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185


186
187
188
189
190
191
192
193
194
195
196
197
	OFOptionsParser *optionsParser;
	of_unichar_t option, mode = '\0';
	of_string_encoding_t encoding = OF_STRING_ENCODING_AUTODETECT;
	OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
	id <Archive> archive;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox = [[OFSandbox alloc] init];
	@try {
		[sandbox setAllowsStdIO: true];
		[sandbox setAllowsReadingFiles: true];
		[sandbox setAllowsWritingFiles: true];
		[sandbox setAllowsCreatingFiles: true];
		[sandbox setAllowsChangingFileAttributes: true];
		[sandbox setAllowsUserDatabaseReading: true];



		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#ifndef OF_AMIGAOS
	[OFLocale addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"];
#endif







|
|
|
|
|
|
|
|
>
>

|
<
<
<







171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189



190
191
192
193
194
195
196
	OFOptionsParser *optionsParser;
	of_unichar_t option, mode = '\0';
	of_string_encoding_t encoding = OF_STRING_ENCODING_AUTODETECT;
	OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
	id <Archive> archive;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox = [OFSandbox sandbox];

	[sandbox setAllowsStdIO: true];
	[sandbox setAllowsReadingFiles: true];
	[sandbox setAllowsWritingFiles: true];
	[sandbox setAllowsCreatingFiles: true];
	[sandbox setAllowsChangingFileAttributes: true];
	[sandbox setAllowsUserDatabaseReading: true];
	/* Dropped after parsing options */
	[sandbox setAllowsUnveil: true];

	[OFApplication activateSandbox: sandbox];



#endif

#ifndef OF_AMIGAOS
	[OFLocale addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"];
#endif
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
346
347






348
349
350
351
352
353
354
355
356






























357
358
359
360
361
362
363
		    @"prog", [OFApplication programName],
		    @"encoding", encodingString)];

		[OFApplication terminateWithStatus: 1];
	}

	remainingArguments = [optionsParser remainingArguments];
	archive = [self openArchiveWithPath: [remainingArguments firstObject]
				       type: type
				       mode: mode
				   encoding: encoding];

	if (outputDir != nil)
		[[OFFileManager defaultManager]
		    changeCurrentDirectoryPath: outputDir];

	switch (mode) {
	case 'a':
	case 'c':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];



















		[archive addFiles: files];
		break;
	case 'l':
		if ([remainingArguments count] != 1)
			help(of_stderr, false, 1);














		[archive listFiles];
		break;
	case 'p':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);








		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];







		[archive printFiles: files];
		break;
	case 'x':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];































		@try {
			[archive extractFiles: files];
		} @catch (OFCreateDirectoryFailedException *e) {
			OFString *error = [OFString
			    stringWithCString: strerror([e errNo])
				     encoding: [OFLocale encoding]];
			[of_stderr writeString: @"\r"];







<
<
<
<
<
<
<
<










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






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





>
>
>
>
>
>
>




>
>
>
>
>
>









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







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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
		    @"prog", [OFApplication programName],
		    @"encoding", encodingString)];

		[OFApplication terminateWithStatus: 1];
	}

	remainingArguments = [optionsParser remainingArguments];









	switch (mode) {
	case 'a':
	case 'c':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: (mode == 'a' ? @"rwc" : @"wc")];

		for (OFString *path in files)
			[sandbox unveilPath: path
				permissions: @"r"];

		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		[archive addFiles: files];
		break;
	case 'l':
		if ([remainingArguments count] != 1)
			help(of_stderr, false, 1);

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: @"r"];
		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		[archive listFiles];
		break;
	case 'p':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: @"r"];
		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		[archive printFiles: files];
		break;
	case 'x':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: @"r"];

		if ([files count] > 0)
			for (OFString *path in files)
				[sandbox unveilPath: path
					permissions: @"wc"];
		else {
			OFString *path = (outputDir != nil
			    ? outputDir : OF_PATH_CURRENT_DIRECTORY);
			/* We need 'r' to change the directory to it. */
			[sandbox unveilPath: path
				permissions: @"rwc"];
		}

		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		if (outputDir != nil)
			[[OFFileManager defaultManager]
			    changeCurrentDirectoryPath: outputDir];

		@try {
			[archive extractFiles: files];
		} @catch (OFCreateDirectoryFailedException *e) {
			OFString *error = [OFString
			    stringWithCString: strerror([e errNo])
				     encoding: [OFLocale encoding]];
			[of_stderr writeString: @"\r"];