From 517e0f0e9ef51779e1408866e85485ee00343082 Mon Sep 17 00:00:00 2001 From: Lionel Dricot Date: Sat, 19 Mar 2022 12:17:02 +0100 Subject: [PATCH] fix a crash when saving a folder --- CHANGELOG | 3 +++ offpunk.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1fa1076..bd442ff 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ # Offpunk History +## 1.2 - Unreleased +- Fixed a crash when trying to save a folder + ## 1.1 - March 18th 2022 - Perfect rendering of pictures with chafa 1.8+ and compatible terminal (Kitty) - timg is supported as an alternative to chafa (with a little glitch) diff --git a/offpunk.py b/offpunk.py index f3862e7..0f9cc9f 100755 --- a/offpunk.py +++ b/offpunk.py @@ -3214,8 +3214,12 @@ see "handler" command to set your own.""" # Don't use _get_active_tmpfile() here, because we want to save the # "source code" of menus, not the rendered view - this way Offpunk # can navigate to it later. - print("Saved to %s" % filename) - shutil.copyfile(gi.get_body(as_file=True), filename) + path = gi.get_body(as_file=True) + if os.path.isdir(path): + print("Can’t save %s because it’s a folder, not a file"%path) + else: + print("Saved to %s" % filename) + shutil.copyfile(path, filename) # Restore gi if necessary if index != None: