From 10a942f7a67fe7f8dc6c17c3115449f5034fb607 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 27 Oct 2015 21:47:24 -0500 Subject: Install without a mode should use 0755, and check FLAG_preserve instead of the global so "install -g 0" doesn't alias to "cp --preserve 0" and error out. through to --preserve 0" --- toys/posix/cp.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'toys') diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 2b032fe6..4be7d3d8 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -1,6 +1,8 @@ /* Copyright 2008 Rob Landley * * See http://opengroup.org/onlinepubs/9699919799/utilities/cp.html + * And http://opengroup.org/onlinepubs/9699919799/utilities/mv.html + * And http://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic.html#INSTALL * * Posix says "cp -Rf dir file" shouldn't delete file, but our -f does. @@ -337,7 +339,7 @@ void cp_main(void) TT.pflags = 7; // preserve=mot umask(0); } - if (CFG_CP_PRESERVE && TT.c.preserve) { + if (CFG_CP_PRESERVE && (toys.optflags & FLAG_preserve)) { char *pre = xstrdup(TT.c.preserve), *s; if (comma_scan(pre, "all", 1)) TT.pflags = ~0; @@ -407,13 +409,21 @@ void mv_main(void) cp_main(); } +// Export cp flags into install's flag context. + +static inline int cp_flag_F(void) { return FLAG_F; }; +static inline int cp_flag_p(void) { return FLAG_p; }; +static inline int cp_flag_v(void) { return FLAG_v; }; + +// Switch to install's flag context #define CLEANUP_cp #define FOR_install #include static int install_node(struct dirtree *try) { - if (TT.i.mode) try->st.st_mode = string_to_mode(TT.i.mode, try->st.st_mode); + try->st.st_mode = (TT.i.mode) + ? string_to_mode(TT.i.mode, try->st.st_mode) : 0755; if (TT.i.group) try->st.st_gid = TT.gid; if (TT.i.user) try->st.st_uid = TT.uid; @@ -450,9 +460,9 @@ void install_main(void) if (toys.optc < 2) error_exit("needs 2 args"); // Translate flags from install to cp - toys.optflags = 4; // Force cp's FLAG_F - if (flags & FLAG_v) toys.optflags |= 8; // cp's FLAG_v - if (flags & (FLAG_p|FLAG_o|FLAG_g)) toys.optflags |= 512; // cp's FLAG_p + toys.optflags = cp_flag_F(); + if (flags & FLAG_v) toys.optflags |= cp_flag_v(); + if (flags & (FLAG_p|FLAG_o|FLAG_g)) toys.optflags |= cp_flag_p(); if (TT.i.user) TT.uid = xgetpwnamid(TT.i.user)->pw_uid; if (TT.i.group) TT.gid = xgetgrnamid(TT.i.group)->gr_gid; -- cgit v1.2.3