setfiles:

* Bug fix: -f option did not work.
* Using bb_simplify_path to remove extra slash for smaller code.
(by Yuichi Nakamura <ynakam@hitachisoft.jp>)
This commit is contained in:
Denis Vlasenko 2007-08-06 02:36:35 +00:00
parent 46340e398e
commit 84d71f33f5

View File

@ -264,28 +264,21 @@ static bool only_changed_user(const char *a, const char *b)
static int restore(const char *file) static int restore(const char *file)
{ {
char *my_file = xstrdup(file); char *my_file;
char *my_file_orig = my_file;
struct stat my_sb; struct stat my_sb;
int i, j, ret; int i, j, ret;
char *context = NULL; char *context = NULL;
char *newcon = NULL; char *newcon = NULL;
bool user_only_changed = 0; bool user_only_changed = 0;
size_t len = strlen(my_file);
int retval = 0; int retval = 0;
/* Skip the extra slashes at the beginning and end, if present. */ my_file = bb_simplify_path(file);
if (file[0] == '/' && file[1] == '/')
my_file++;
if (len > 1 && my_file[len - 1] == '/')
my_file[len - 1] = '\0';
i = match(my_file, &my_sb, &newcon); i = match(my_file, &my_sb, &newcon);
if (i < 0) /* No matching specification. */ if (i < 0) /* No matching specification. */
goto out; goto out;
if (FLAG_p_progress) { if (FLAG_p_progress) {
count++; count++;
if (count % 0x400 == 0) { /* every 1024 times */ if (count % 0x400 == 0) { /* every 1024 times */
@ -386,7 +379,7 @@ static int restore(const char *file)
out: out:
freecon(context); freecon(context);
freecon(newcon); freecon(newcon);
free(my_file_orig); free(my_file);
return retval; return retval;
err: err:
retval--; /* -1 */ retval--; /* -1 */
@ -499,7 +492,6 @@ int setfiles_main(int argc, char **argv)
struct stat sb; struct stat sb;
int rc, i = 0; int rc, i = 0;
const char *input_filename = NULL; const char *input_filename = NULL;
int use_input_file = 0;
char *buf = NULL; char *buf = NULL;
size_t buf_len; size_t buf_len;
int flags; int flags;
@ -591,7 +583,6 @@ int setfiles_main(int argc, char **argv)
rootpathlen = strlen(rootpath); rootpathlen = strlen(rootpath);
} }
if (flags & OPT_s) { if (flags & OPT_s) {
use_input_file = 1;
input_filename = "-"; input_filename = "-";
add_assoc = 0; add_assoc = 0;
} }
@ -621,7 +612,7 @@ int setfiles_main(int argc, char **argv)
exit(1); exit(1);
} }
if (use_input_file) { if (input_filename) {
ssize_t len; ssize_t len;
FILE *f = stdin; FILE *f = stdin;