summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-06-10 23:02:40 +0200
committerLennart Poettering <lennart@poettering.net>2014-06-10 23:02:40 +0200
commit849958d1ba3533c953fad46d4d41c0ec6e48316d (patch)
tree4002001e577cf348fe5df3fc4aa359bd21428a52 /src/tmpfiles
parentcde684a2932d3c8cbb9b3374aec27a1c20ba75fa (diff)
tmpfiles: add new "C" line for copying files or directories
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 48dc619d94..6745c23a15 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -53,6 +53,7 @@
#include "capability.h"
#include "specifier.h"
#include "build.h"
+#include "copy.h"
/* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
* them in the file system. This is intended to be used to create
@@ -69,6 +70,7 @@ typedef enum ItemType {
CREATE_SYMLINK = 'L',
CREATE_CHAR_DEVICE = 'c',
CREATE_BLOCK_DEVICE = 'b',
+ COPY_FILES = 'C',
ADJUST_MODE = 'm',
/* These ones take globs */
@@ -671,6 +673,19 @@ static int create_item(Item *i) {
return r;
break;
+ case COPY_FILES:
+ r = copy_tree(i->argument, i->path);
+ if (r < 0) {
+ log_error("Failed to copy files: %s", strerror(-r));
+ return r;
+ }
+
+ r = item_set_perms(i, i->path);
+ if (r < 0)
+ return r;
+
+ break;
+
case WRITE_FILE:
r = glob_item(i, write_one_file);
if (r < 0)
@@ -849,6 +864,7 @@ static int remove_item_instance(Item *i, const char *instance) {
case RELABEL_PATH:
case RECURSIVE_RELABEL_PATH:
case WRITE_FILE:
+ case COPY_FILES:
case ADJUST_MODE:
break;
@@ -895,6 +911,7 @@ static int remove_item(Item *i) {
case RELABEL_PATH:
case RECURSIVE_RELABEL_PATH:
case WRITE_FILE:
+ case COPY_FILES:
case ADJUST_MODE:
break;
@@ -967,6 +984,7 @@ static int clean_item(Item *i) {
case CREATE_DIRECTORY:
case TRUNCATE_DIRECTORY:
case IGNORE_PATH:
+ case COPY_FILES:
clean_item_instance(i, i->path);
break;
case IGNORE_DIRECTORY_PATH:
@@ -1036,7 +1054,8 @@ static bool item_equal(Item *a, Item *b) {
if ((a->type == CREATE_FILE ||
a->type == TRUNCATE_FILE ||
a->type == WRITE_FILE ||
- a->type == CREATE_SYMLINK) &&
+ a->type == CREATE_SYMLINK ||
+ a->type == COPY_FILES) &&
!streq_ptr(a->argument, b->argument))
return false;
@@ -1159,6 +1178,20 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
}
break;
+ case COPY_FILES:
+ if (!i->argument) {
+ log_error("[%s:%u] Copy files requires argument.", fname, line);
+ return -EBADMSG;
+ }
+
+ if (!path_is_absolute(i->argument)) {
+ log_error("[%s:%u] Source path is not absolute.", fname, line);
+ return -EBADMSG;
+ }
+
+ path_kill_slashes(i->argument);
+ break;
+
case CREATE_CHAR_DEVICE:
case CREATE_BLOCK_DEVICE: {
unsigned major, minor;