- char *dest = last;
- if (isdir)
- dest = concat_path_file(last, basename(arg));
- if (copy_file(arg, dest, copy_flags)) {
- /* copy is not made */
- ret = EXIT_FAILURE;
- goto next;
+ char *dest;
+
+ if (opts & OPT_DIRECTORY) {
+ dest = arg;
+ /* GNU coreutils 6.9 does not set uid:gid
+ * on intermediate created directories
+ * (only on last one) */
+ if (bb_make_directory(dest, 0755, mkdir_flags)) {
+ ret = EXIT_FAILURE;
+ goto next;
+ }
+ } else {
+ dest = last;
+ if (opts & OPT_MKDIR_LEADING) {
+ char *ddir = xstrdup(dest);
+ bb_make_directory(dirname(ddir), 0755, mkdir_flags);
+ /* errors are not checked. copy_file
+ * will fail if dir is not created. */
+ free(ddir);
+ }
+ if (isdir)
+ dest = concat_path_file(last, bb_basename(arg));
+ if (copy_file(arg, dest, copy_flags) != 0) {
+ /* copy is not made */
+ ret = EXIT_FAILURE;
+ goto next;
+ }
+ if (opts & OPT_STRIP) {
+ char *args[4];
+ args[0] = (char*)"strip";
+ args[1] = (char*)"-p"; /* -p --preserve-dates */
+ args[2] = dest;
+ args[3] = NULL;
+ if (spawn_and_wait(args)) {
+ bb_perror_msg("strip");
+ ret = EXIT_FAILURE;
+ }
+ }