Skip to content

run_cmd function fails with a Not a directory error if the command is not found #269

@mschmidtkorth

Description

@mschmidtkorth

Error
When backing up dotfiles, some operations result in a NotADirectoryError exception, forcing the backup process to stop.

Example: Not a directory: 'apm'

I do not have Atom installed and therefore no 'apm' folder.

Intended behavior
Check if folder exists, if not ignore and do not attempt to backup.

Traceback (most recent call last):
  File "/usr/local/bin/shallow-backup", line 8, in <module>
    sys.exit(cli())
  File "/Users/mschmidtkorth/Library/Python/3.7/lib/python/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/mschmidtkorth/Library/Python/3.7/lib/python/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/mschmidtkorth/Library/Python/3.7/lib/python/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/mschmidtkorth/Library/Python/3.7/lib/python/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/shallow_backup/__main__.py", line 147, in cli
    backup_all(dotfiles_path, packages_path, fonts_path, configs_path)
  File "/usr/local/lib/python3.7/site-packages/shallow_backup/backup.py", line 188, in backup_all
    backup_packages(packages_path, skip)
  File "/usr/local/lib/python3.7/site-packages/shallow_backup/backup.py", line 142, in backup_packages
    run_cmd_write_stdout(command, dest)
  File "/usr/local/lib/python3.7/site-packages/shallow_backup/utils.py", line 30, in run_cmd_write_stdout
    process = run_cmd(command)
  File "/usr/local/lib/python3.7/site-packages/shallow_backup/utils.py", line 15, in run_cmd
    process = sp.run(command.split(), stdout=sp.PIPE, stderr=sp.DEVNULL)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 488, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
NotADirectoryError: [Errno 20] Not a directory: 'apm'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions