md5_sha1_sum: fix mishandling when run as /bin/md5sum (with path)
chown/chgrp: completely match coreutils 6.8 wrt symlink handling function old new delta recursive_action 411 422 +11 arith 2033 2042 +9 collect_blk 467 474 +7 dhcprelay_main 1122 1125 +3 fsck_main 1909 1911 +2 singlemount 4555 4547 -8 xmalloc_realpath 14 - -14 get_lcm 123 105 -18 ed_main 3111 3084 -27 chown_main 217 183 -34 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 5/4 up/down: 32/-101) Total: -69 bytes text data bss dec hex filename 684132 2744 14000 700876 ab1cc busybox_old 684060 2744 14000 700804 ab184 busybox_unstripped
This commit is contained in:
parent
42b3dea9bf
commit
d166f83d74
@ -65,6 +65,7 @@ int chown_main(int argc, char **argv);
|
|||||||
int chown_main(int argc, char **argv)
|
int chown_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int retval = EXIT_SUCCESS;
|
int retval = EXIT_SUCCESS;
|
||||||
|
int flags;
|
||||||
chown_fptr chown_func;
|
chown_fptr chown_func;
|
||||||
|
|
||||||
opt_complementary = "-2";
|
opt_complementary = "-2";
|
||||||
@ -80,23 +81,21 @@ int chown_main(int argc, char **argv)
|
|||||||
chown_func = lchown;
|
chown_func = lchown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flags = ACTION_DEPTHFIRST; /* match coreutils order */
|
||||||
|
if (OPT_RECURSE)
|
||||||
|
flags |= ACTION_RECURSE;
|
||||||
|
if (OPT_TRAVERSE_TOP)
|
||||||
|
flags |= ACTION_FOLLOWLINKS_L0; /* -H/-L: follow links on depth 0 */
|
||||||
|
if (OPT_TRAVERSE)
|
||||||
|
flags |= ACTION_FOLLOWLINKS; /* follow links if -L */
|
||||||
|
|
||||||
parse_chown_usergroup_or_die(&ugid, argv[0]);
|
parse_chown_usergroup_or_die(&ugid, argv[0]);
|
||||||
|
|
||||||
/* Ok, ready to do the deed now */
|
/* Ok, ready to do the deed now */
|
||||||
argv++;
|
argv++;
|
||||||
do {
|
do {
|
||||||
char *arg = *argv;
|
if (!recursive_action(*argv,
|
||||||
|
flags, /* flags */
|
||||||
if (OPT_TRAVERSE_TOP) {
|
|
||||||
/* resolves symlink (even recursive) */
|
|
||||||
arg = xmalloc_realpath(arg);
|
|
||||||
if (!arg)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!recursive_action(arg,
|
|
||||||
(OPT_RECURSE ? ACTION_RECURSE : 0) | /* recurse */
|
|
||||||
(OPT_TRAVERSE ? ACTION_FOLLOWLINKS : 0),/* follow links if -L */
|
|
||||||
fileAction, /* file action */
|
fileAction, /* file action */
|
||||||
fileAction, /* dir action */
|
fileAction, /* dir action */
|
||||||
chown_func, /* user data */
|
chown_func, /* user data */
|
||||||
@ -104,9 +103,6 @@ int chown_main(int argc, char **argv)
|
|||||||
) {
|
) {
|
||||||
retval = EXIT_FAILURE;
|
retval = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OPT_TRAVERSE_TOP)
|
|
||||||
free(arg);
|
|
||||||
} while (*++argv);
|
} while (*++argv);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
@ -137,8 +133,10 @@ create() {
|
|||||||
tst() {
|
tst() {
|
||||||
create test1
|
create test1
|
||||||
create test2
|
create test2
|
||||||
(cd test1; $t1 $1)
|
echo "[$1]" >>test1.out
|
||||||
(cd test2; $t2 $1)
|
echo "[$1]" >>test2.out
|
||||||
|
(cd test1; $t1 $1) >>test1.out 2>&1
|
||||||
|
(cd test2; $t2 $1) >>test2.out 2>&1
|
||||||
(cd test1; ls -lnR) >out1
|
(cd test1; ls -lnR) >out1
|
||||||
(cd test2; ls -lnR) >out2
|
(cd test2; ls -lnR) >out2
|
||||||
echo "chown $1" >out.diff
|
echo "chown $1" >out.diff
|
||||||
@ -152,18 +150,22 @@ tst_for_each() {
|
|||||||
tst "$1 1:1 linkfile"
|
tst "$1 1:1 linkfile"
|
||||||
}
|
}
|
||||||
echo "If script produced 'out.diff' file, then at least one testcase failed"
|
echo "If script produced 'out.diff' file, then at least one testcase failed"
|
||||||
|
>test1.out
|
||||||
|
>test2.out
|
||||||
# These match coreutils 6.8:
|
# These match coreutils 6.8:
|
||||||
tst_for_each ""
|
tst_for_each "-v"
|
||||||
tst_for_each "-R"
|
tst_for_each "-vR"
|
||||||
tst_for_each "-RP"
|
tst_for_each "-vRP"
|
||||||
tst_for_each "-RL"
|
tst_for_each "-vRL"
|
||||||
tst_for_each "-RH"
|
tst_for_each "-vRH"
|
||||||
tst_for_each "-h"
|
tst_for_each "-vh"
|
||||||
tst_for_each "-hR"
|
tst_for_each "-vhR"
|
||||||
tst_for_each "-hRP"
|
tst_for_each "-vhRP"
|
||||||
# Below: with "chown linkdir" coreutils 6.8 will chown linkdir _target_,
|
tst_for_each "-vhRL"
|
||||||
# we lchown _the link_. I believe we are "more correct".
|
tst_for_each "-vhRH"
|
||||||
#tst_for_each "-hRL"
|
# Fix `name' in coreutils output
|
||||||
#tst_for_each "-hRH"
|
sed 's/`/'"'"'/g' -i test2.out
|
||||||
|
# Compare us with coreutils output
|
||||||
|
diff -u test1.out test2.out
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -84,7 +84,7 @@ int md5_sha1_sum_main(int argc, char **argv)
|
|||||||
uint8_t *hash_value;
|
uint8_t *hash_value;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
hash_algo_t hash_algo = ENABLE_MD5SUM
|
hash_algo_t hash_algo = ENABLE_MD5SUM
|
||||||
? (ENABLE_SHA1SUM ? (**argv=='m' ? HASH_MD5 : HASH_SHA1) : HASH_MD5)
|
? (ENABLE_SHA1SUM ? (applet_name[0] == 'm' ? HASH_MD5 : HASH_SHA1) : HASH_MD5)
|
||||||
: HASH_SHA1;
|
: HASH_SHA1;
|
||||||
|
|
||||||
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK)
|
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK)
|
||||||
|
@ -214,15 +214,16 @@ extern int is_directory(const char *name, int followLinks, struct stat *statBuf)
|
|||||||
extern int remove_file(const char *path, int flags);
|
extern int remove_file(const char *path, int flags);
|
||||||
extern int copy_file(const char *source, const char *dest, int flags);
|
extern int copy_file(const char *source, const char *dest, int flags);
|
||||||
enum {
|
enum {
|
||||||
ACTION_RECURSE = (1 << 0),
|
ACTION_RECURSE = (1 << 0),
|
||||||
ACTION_FOLLOWLINKS = (1 << 1),
|
ACTION_FOLLOWLINKS = (1 << 1),
|
||||||
ACTION_DEPTHFIRST = (1 << 2),
|
ACTION_FOLLOWLINKS_L0 = (1 << 2),
|
||||||
/*ACTION_REVERSE = (1 << 3), - unused */
|
ACTION_DEPTHFIRST = (1 << 3),
|
||||||
|
/*ACTION_REVERSE = (1 << 4), - unused */
|
||||||
};
|
};
|
||||||
extern int recursive_action(const char *fileName, unsigned flags,
|
extern int recursive_action(const char *fileName, unsigned flags,
|
||||||
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
|
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
|
||||||
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
|
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
|
||||||
void* userData, const unsigned depth);
|
void* userData, unsigned depth);
|
||||||
extern int device_open(const char *device, int mode);
|
extern int device_open(const char *device, int mode);
|
||||||
extern int get_console_fd(void);
|
extern int get_console_fd(void);
|
||||||
extern char *find_block_device(const char *path);
|
extern char *find_block_device(const char *path);
|
||||||
|
@ -46,7 +46,7 @@ int recursive_action(const char *fileName,
|
|||||||
int (*fileAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
|
int (*fileAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
|
||||||
int (*dirAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
|
int (*dirAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
|
||||||
void* userData,
|
void* userData,
|
||||||
const unsigned depth)
|
unsigned depth)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
int status;
|
int status;
|
||||||
@ -55,12 +55,13 @@ int recursive_action(const char *fileName,
|
|||||||
|
|
||||||
if (!fileAction) fileAction = true_action;
|
if (!fileAction) fileAction = true_action;
|
||||||
if (!dirAction) dirAction = true_action;
|
if (!dirAction) dirAction = true_action;
|
||||||
status = (flags & ACTION_FOLLOWLINKS ? stat : lstat)(fileName, &statbuf);
|
|
||||||
|
|
||||||
|
status = ACTION_FOLLOWLINKS; /* hijack a variable for bitmask... */
|
||||||
|
if (!depth) status = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0;
|
||||||
|
status = ((flags & status) ? stat : lstat)(fileName, &statbuf);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
#ifdef DEBUG_RECURS_ACTION
|
#ifdef DEBUG_RECURS_ACTION
|
||||||
bb_error_msg("status=%d followLinks=%d TRUE=%d",
|
bb_error_msg("status=%d flags=%x", status, flags);
|
||||||
status, flags & ACTION_FOLLOWLINKS, TRUE);
|
|
||||||
#endif
|
#endif
|
||||||
goto done_nak_warn;
|
goto done_nak_warn;
|
||||||
}
|
}
|
||||||
@ -82,9 +83,8 @@ int recursive_action(const char *fileName,
|
|||||||
|
|
||||||
if (!(flags & ACTION_DEPTHFIRST)) {
|
if (!(flags & ACTION_DEPTHFIRST)) {
|
||||||
status = dirAction(fileName, &statbuf, userData, depth);
|
status = dirAction(fileName, &statbuf, userData, depth);
|
||||||
if (!status) {
|
if (!status)
|
||||||
goto done_nak_warn;
|
goto done_nak_warn;
|
||||||
}
|
|
||||||
if (status == SKIP)
|
if (status == SKIP)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -103,23 +103,23 @@ int recursive_action(const char *fileName,
|
|||||||
nextFile = concat_subpath_file(fileName, next->d_name);
|
nextFile = concat_subpath_file(fileName, next->d_name);
|
||||||
if (nextFile == NULL)
|
if (nextFile == NULL)
|
||||||
continue;
|
continue;
|
||||||
/* now descend into it, forcing recursion. */
|
/* now descend into it (NB: ACTION_RECURSE is set in flags) */
|
||||||
if (!recursive_action(nextFile, flags | ACTION_RECURSE,
|
if (!recursive_action(nextFile, flags, fileAction, dirAction, userData, depth+1))
|
||||||
fileAction, dirAction, userData, depth+1)) {
|
|
||||||
status = FALSE;
|
status = FALSE;
|
||||||
}
|
|
||||||
free(nextFile);
|
free(nextFile);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
if ((flags & ACTION_DEPTHFIRST) &&
|
|
||||||
!dirAction(fileName, &statbuf, userData, depth)) {
|
if (flags & ACTION_DEPTHFIRST) {
|
||||||
|
if (!dirAction(fileName, &statbuf, userData, depth))
|
||||||
goto done_nak_warn;
|
goto done_nak_warn;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!status)
|
if (!status)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
done_nak_warn:
|
|
||||||
|
done_nak_warn:
|
||||||
bb_perror_msg("%s", fileName);
|
bb_perror_msg("%s", fileName);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user