@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -142,10 +142,31 @@ [OFStdErr writeLine: OF_LOCALIZED( @"writing_not_supported", @"Writing archives of type %[type] is not (yet) supported!", @"type", type)]; } + +static void +addFiles(id archive, OFArray OF_GENERIC(OFString *) *files) +{ + OFMutableArray *expandedFiles = + [OFMutableArray arrayWithCapacity: files.count]; + OFFileManager *fileManager = [OFFileManager defaultManager]; + + for (OFString *file in files) { + OFFileAttributes attributes = + [fileManager attributesOfItemAtPath: file]; + + if ([attributes.fileType isEqual: OFFileTypeDirectory]) + [expandedFiles addObjectsFromArray: + [fileManager subpathsOfDirectoryAtPath: file]]; + else + [expandedFiles addObject: file]; + } + + [archive addFiles: expandedFiles]; +} @implementation OFArc - (void)applicationDidFinishLaunching { OFString *outputDir, *encodingString, *type; @@ -334,11 +355,11 @@ openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; - [archive addFiles: files]; + addFiles(archive, files); break; case 'l': if (remainingArguments.count != 1) help(OFStdErr, false, 1);