diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-07-23 10:57:11 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-07-23 10:57:11 +0300 |
commit | 6377e0dfecb9836aabca5d11f2dcfa7d722115af (patch) | |
tree | 09faa54213cee5283daff7750543f68f777bc4f0 | |
parent | 3ac72b91f69c1cdfb61babb1ae3dbc69e2065eac (diff) | |
download | cpio-6377e0dfecb9836aabca5d11f2dcfa7d722115af.tar.gz cpio-6377e0dfecb9836aabca5d11f2dcfa7d722115af.tar.bz2 |
Improve handling of -D in copy-pass mode.
* gnulib.modules: Add xgetcwd.
* src/copypass.c (process_copy_pass): Convert directory_name
to absolute if -D option was given.
-rw-r--r-- | gnulib.modules | 1 | ||||
-rw-r--r-- | src/copypass.c | 23 |
2 files changed, 20 insertions, 4 deletions
diff --git a/gnulib.modules b/gnulib.modules index 335cd2a..002714b 100644 --- a/gnulib.modules +++ b/gnulib.modules | |||
@@ -27,3 +27,4 @@ unlocked-io | |||
27 | utimens | 27 | utimens |
28 | xalloc | 28 | xalloc |
29 | xalloc-die | 29 | xalloc-die |
30 | xgetcwd | ||
diff --git a/src/copypass.c b/src/copypass.c index 1fcc8b3..5b1d594 100644 --- a/src/copypass.c +++ b/src/copypass.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "dstring.h" | 27 | #include "dstring.h" |
28 | #include "extern.h" | 28 | #include "extern.h" |
29 | #include "paxlib.h" | 29 | #include "paxlib.h" |
30 | #include "xgetcwd.h" | ||
30 | 31 | ||
31 | #ifndef HAVE_LCHOWN | 32 | #ifndef HAVE_LCHOWN |
32 | # define lchown chown | 33 | # define lchown chown |
@@ -51,7 +52,7 @@ process_copy_pass () | |||
51 | { | 52 | { |
52 | dynamic_string input_name; /* Name of file from stdin. */ | 53 | dynamic_string input_name; /* Name of file from stdin. */ |
53 | dynamic_string output_name; /* Name of new file. */ | 54 | dynamic_string output_name; /* Name of new file. */ |
54 | int dirname_len; /* Length of `directory_name'. */ | 55 | size_t dirname_len; /* Length of `directory_name'. */ |
55 | int res; /* Result of functions. */ | 56 | int res; /* Result of functions. */ |
56 | char *slash; /* For moving past slashes in input name. */ | 57 | char *slash; /* For moving past slashes in input name. */ |
57 | struct stat in_file_stat; /* Stat record for input file. */ | 58 | struct stat in_file_stat; /* Stat record for input file. */ |
@@ -68,10 +69,24 @@ process_copy_pass () | |||
68 | created files */ | 69 | created files */ |
69 | 70 | ||
70 | /* Initialize the copy pass. */ | 71 | /* Initialize the copy pass. */ |
71 | dirname_len = strlen (directory_name); | ||
72 | ds_init (&input_name, 128); | 72 | ds_init (&input_name, 128); |
73 | ds_init (&output_name, dirname_len + 2); | 73 | |
74 | strcpy (output_name.ds_string, directory_name); | 74 | dirname_len = strlen (directory_name); |
75 | if (change_directory_option && !ISSLASH (directory_name[0])) | ||
76 | { | ||
77 | char *pwd = xgetcwd (); | ||
78 | |||
79 | dirname_len += strlen (pwd) + 1; | ||
80 | ds_init (&output_name, dirname_len + 2); | ||
81 | strcpy (output_name.ds_string, pwd); | ||
82 | strcat (output_name.ds_string, "/"); | ||
83 | strcat (output_name.ds_string, directory_name); | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | ds_init (&output_name, dirname_len + 2); | ||
88 | strcpy (output_name.ds_string, directory_name); | ||
89 | } | ||
75 | output_name.ds_string[dirname_len] = '/'; | 90 | output_name.ds_string[dirname_len] = '/'; |
76 | output_is_seekable = true; | 91 | output_is_seekable = true; |
77 | 92 | ||