From 8700e271d95435ede5a98b58b29ba972f1310ed0 Mon Sep 17 00:00:00 2001 From: Logan Arens Date: Wed, 9 Oct 2019 22:47:50 -0400 Subject: [PATCH 1/5] "beet update" now confirms that the library path exists before updating. Fixes #1934. --- beets/ui/commands.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 7941be46b..e9afa2f18 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1185,8 +1185,13 @@ def update_items(lib, query, album, move, pretend, fields): def update_func(lib, opts, args): + # Verify that the library folder exists. (disk isn't unmounted, for example) + if not os.path.exists(lib.directory): + ui.print_("Library path is unavailable or does not exist.") + if not ui.input_yn("Are you sure you want to continue (y/n)?", True): + return update_items(lib, decargs(args), opts.album, ui.should_move(opts.move), - opts.pretend, opts.fields) + opts.pretend, opts.fields) update_cmd = ui.Subcommand( From 0030a2218c62679444288d8196f569671799f8c8 Mon Sep 17 00:00:00 2001 From: Logan Arens Date: Wed, 9 Oct 2019 23:17:07 -0400 Subject: [PATCH 2/5] Small cosmetic changes to meet flake8 standards --- beets/ui/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index e9afa2f18..94baced22 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1185,13 +1185,13 @@ def update_items(lib, query, album, move, pretend, fields): def update_func(lib, opts, args): - # Verify that the library folder exists. (disk isn't unmounted, for example) + # Verify that the library folder exists to prevent accidental wipes. if not os.path.exists(lib.directory): ui.print_("Library path is unavailable or does not exist.") if not ui.input_yn("Are you sure you want to continue (y/n)?", True): return update_items(lib, decargs(args), opts.album, ui.should_move(opts.move), - opts.pretend, opts.fields) + opts.pretend, opts.fields) update_cmd = ui.Subcommand( From 72fcceac99b5609f2becbd0c101f90353c46e55e Mon Sep 17 00:00:00 2001 From: Logan Arens Date: Sat, 12 Oct 2019 12:22:29 -0400 Subject: [PATCH 3/5] Added changelog entry. --- docs/changelog.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 963863ae8..16d5f7d1c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -116,6 +116,11 @@ Fixes: :bug:`3242` * Fix a bug that caused a crash when tagging items with the beatport plugin. :bug:`3374` +* ``beet update`` will now confirm that the user still wants to update if + their library folder cannot be found, preventing the user from accidentally + wiping out their beets database. + Thanks to :user:`logan-arens`. + :bug:`1934` For plugin developers: From baf4953ac0ceeca7a91f9e7d6db718da58b38508 Mon Sep 17 00:00:00 2001 From: Logan Arens Date: Sat, 12 Oct 2019 12:25:18 -0400 Subject: [PATCH 4/5] Library path is printed if `update` cannot find it --- beets/ui/commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 94baced22..a6d712dbf 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1188,6 +1188,7 @@ def update_func(lib, opts, args): # Verify that the library folder exists to prevent accidental wipes. if not os.path.exists(lib.directory): ui.print_("Library path is unavailable or does not exist.") + ui.print_(lib.directory) if not ui.input_yn("Are you sure you want to continue (y/n)?", True): return update_items(lib, decargs(args), opts.album, ui.should_move(opts.move), From b2ef1941aaf624ee52551a918baaadc3873c0db7 Mon Sep 17 00:00:00 2001 From: Logan Arens Date: Sat, 12 Oct 2019 14:00:44 -0400 Subject: [PATCH 5/5] Changed library check from existence to directory --- beets/ui/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index a6d712dbf..56f9ad1f5 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1186,7 +1186,7 @@ def update_items(lib, query, album, move, pretend, fields): def update_func(lib, opts, args): # Verify that the library folder exists to prevent accidental wipes. - if not os.path.exists(lib.directory): + if not os.path.isdir(lib.directory): ui.print_("Library path is unavailable or does not exist.") ui.print_(lib.directory) if not ui.input_yn("Are you sure you want to continue (y/n)?", True):