Skip to content

zip command does not work correctly on Linux and Mac #217

Description

@badc0decafe

The zip command has two related issues on Linux and macOS:

1. Missing -r flag

Attempting to use the -r flag for recursive directory compression fails because it is not implemented in Falcon Toolkit. While Windows operates in recursive mode by default, macOS and Linux don't and will instead only compress the outer directory in a larger directory tree resulting in a zip containing only an empty directory.

While a workaround will be available on Linux in the form of the tar command #216, this is not available on macOS.

Falcon RTR already supports the -r flag for zip so I was able to add the feature for myself as follows:

falcon_toolkit/shell/parsers.py

zip_argparser.add_argument(
    "-r",
    help="[Linux/Mac] Travel the directory structure recursively",
    action="store_true",
    dest="recursive",
)

falcon_toolkit/shell/prompt.py

@with_argparser(PARSERS.zip, preserve_quotes=True)
def do_zip(self, args):
    """Compress a file or directory into a zip file."""
    if args.recursive:
        command = f"zip -r {args.source} {args.destination}"
    else:
        command = f"zip {args.source} {args.destination}"
    self.send_generic_command(command)

On Windows, RTR will generate a helpful error message if you try to add the -r argument because while the proposed help text does specify it is a Linux/Mac option, we don't actually have a way to or want to restrict arguments to a particular OS #95

2. The source and destination arguments are reversed on Linux and macOS

Following on from the documentation point above, Linux and macOS actually flip the order of the source and destination so the correct order for Linux would be:

zip [-r] destination source

Ideally I think we should note in the help text that the arguments are reversed on Linux and macOS to avoid frustration where the command follows the help text precisely but the command doesn't work.


I'd be happy to open a PR if this implementation looks good.

I tested these changes and was able to generate recursive zips on macOS and Linux but let me know if this touches any additional code paths, I've missed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions