[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH] files: do not silently ignore an invalid backup dir
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH] files: do not silently ignore an invalid backup directory, but die |
Date: |
Sun, 6 Aug 2017 09:11:06 +0200 |
It would be horrible if the user expects to find numbered backups
of all the files that were changed but they are NOT there because
the config file contains a typo or the relevant directory was moved
or renamed or something. So... if the specified backup directory
is not usable, nano should complain and simply not start up.
---
src/files.c | 25 ++++++++++---------------
src/nano.c | 8 ++++----
2 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/src/files.c b/src/files.c
index 573c449a..16bea02f 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1490,23 +1490,18 @@ int prompt_failed_backupwrite(const char *filename)
return response;
}
-/* Transform the specified backup directory to an absolute path. */
+/* Transform the specified backup directory to an absolute path,
+ * and verify that it is usable. */
void init_backup_dir(void)
{
- char *full_backup_dir = get_full_path(backup_dir);
-
- /* When we can't get an absolute path, or it's not a directory,
- * cancel the making of backups. */
- if (full_backup_dir == NULL ||
- full_backup_dir[strlen(full_backup_dir) - 1] != '/') {
- free(full_backup_dir);
- free(backup_dir);
- backup_dir = NULL;
- } else {
- free(backup_dir);
- backup_dir = full_backup_dir;
- snuggly_fit(&backup_dir);
- }
+ backup_dir = free_and_assign(backup_dir, get_full_path(backup_dir));
+
+ /* If we can't get an absolute path (which means it doesn't exist or
+ isn't accessible), or it's not a directory, fail. */
+ if (backup_dir == NULL || backup_dir[strlen(backup_dir) - 1] != '/')
+ die(_("Invalid backup directory\n"));
+
+ snuggly_fit(&backup_dir);
}
#endif /* !NANO_TINY */
diff --git a/src/nano.c b/src/nano.c
index 44b83c9d..3526e72d 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2374,10 +2374,10 @@ int main(int argc, char **argv)
#endif /* !DISABLE_HISTORIES */
#ifndef NANO_TINY
- /* If a backup directory was specified and we're not in restricted mode,
- * make sure the path exists and is a directory, so that backup files can
- * be saved there. */
- if (backup_dir != NULL && !ISSET(RESTRICTED))
+ /* If a backup directory was specified and backups are enabled and
+ * we're not in restricted mode, make sure the path exists and is
+ * a directory, so that backup files can be saved there. */
+ if (backup_dir != NULL && !ISSET(RESTRICTED) && ISSET(BACKUP_FILE))
init_backup_dir();
#endif
--
2.13.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] [PATCH] files: do not silently ignore an invalid backup directory, but die,
Benno Schulenberg <=