41 lines
1.3 KiB
Diff
41 lines
1.3 KiB
Diff
From 8ad9e9179ec806ec1031c94b218ae6ef9dc11c28 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Ond=C5=99ej=20Poho=C5=99elsk=C3=BD?= <opohorel@redhat.com>
|
|
Date: Wed, 2 Jul 2025 11:58:41 +0200
|
|
Subject: [PATCH] crontab: Fix backup failure when ~/.cache directory missing
|
|
|
|
Create ~/.cache parent directory before creating ~/.cache/crontab backup
|
|
directory to prevent "mkdir: No such file or directory" errors when users
|
|
edit crontabs and their cache directory doesn't exist.
|
|
---
|
|
src/crontab.c | 13 +++++++++++++
|
|
1 file changed, 13 insertions(+)
|
|
|
|
diff --git a/src/crontab.c b/src/crontab.c
|
|
index c11dc81..f6fae67 100644
|
|
--- a/src/crontab.c
|
|
+++ b/src/crontab.c
|
|
@@ -578,7 +578,20 @@ static int backup_crontab(const char *crontab_path) {
|
|
exit(ERROR_EXIT);
|
|
}
|
|
|
|
+ /* Try to create parent directory if needed */
|
|
if (stat(backup_dir, &sb) < OK && errno == ENOENT) {
|
|
+ char *last_slash = strrchr(backup_dir, '/');
|
|
+ if (last_slash && last_slash != backup_dir) {
|
|
+ char parent_dir[MAX_FNAME];
|
|
+ size_t parent_len = last_slash - backup_dir;
|
|
+
|
|
+ if (parent_len < sizeof(parent_dir)) {
|
|
+ strncpy(parent_dir, backup_dir, parent_len);
|
|
+ parent_dir[parent_len] = '\0';
|
|
+ mkdir(parent_dir, 0755);
|
|
+ }
|
|
+ }
|
|
+
|
|
if (OK != mkdir(backup_dir, 0755)) {
|
|
fprintf(stderr, "%s: ", backup_dir);
|
|
perror("mkdir");
|
|
--
|
|
2.50.1
|
|
|