TT#111357 also apply chown to created parent dirs

Change-Id: I6300e49816f83561f3eafffc893cfb1efc334b6f
pull/1218/head
Richard Fuchs 5 years ago
parent b8b395e21f
commit 8aecb6a98a

@ -40,7 +40,7 @@ int output_mixed;
int output_single;
int output_enabled = 1;
mode_t output_chmod;
mode_t output_chmod_dir = 0700;
mode_t output_chmod_dir;
uid_t output_chown = -1;
gid_t output_chgrp = -1;
char *output_pattern = NULL;

@ -47,6 +47,41 @@ int output_add(output_t *output, AVFrame *frame) {
}
static void create_parent_dirs(char *dir) {
char *p = dir;
// skip root
if (*p == G_DIR_SEPARATOR)
p++;
while (1) {
// find next dir separator
p = strchr(p, G_DIR_SEPARATOR);
if (!p)
break;
// check/create dir
*p = '\0';
// create with 0700 first, then chmod
if (mkdir(dir, 0700)) {
int existed = errno == EEXIST;
if (!existed)
ilog(LOG_WARN, "Failed to create directory '%s': %s", dir, strerror(errno));
*p = G_DIR_SEPARATOR;
if (!existed) // no point in continuing
break;
continue;
}
if (output_chmod_dir && chmod(dir, output_chmod_dir))
ilog(LOG_WARN, "Failed to change mode of '%s': %s", dir, strerror(errno));
if (output_chown != -1 || output_chgrp != -1)
if (chown(dir, output_chown, output_chgrp))
ilog(LOG_WARN, "Failed to change owner/group of '%s': %s",
dir, strerror(errno));
*p++ = G_DIR_SEPARATOR;
}
}
output_t *output_new(const char *path, const char *call, const char *type) {
// construct output file name
time_t now = time(NULL);
@ -126,16 +161,7 @@ done:;
ret->file_format = output_file_format;
ret->encoder = encoder_new();
// create parent directories if needed
char *last_sep = strrchr(ret->full_filename, G_DIR_SEPARATOR);
if (last_sep) {
*last_sep = '\0';
if (g_mkdir_with_parents(ret->full_filename, output_chmod_dir))
ilog(LOG_WARN, "Failed to create (parent) directory for '%s': %s",
ret->full_filename, strerror(errno));
*last_sep = G_DIR_SEPARATOR;
}
create_parent_dirs(ret->full_filename);
g_string_free(f, FALSE);

Loading…
Cancel
Save