mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
Use generic flag names.
This commit is contained in:
parent
9ff9325e60
commit
01441036e9
@ -42,22 +42,22 @@ extern int cp_main(int argc, char **argv)
|
|||||||
while ((opt = getopt(argc, argv, "adfipR")) != -1)
|
while ((opt = getopt(argc, argv, "adfipR")) != -1)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
flags |= CP_PRESERVE_STATUS | CP_RECUR;
|
flags |= FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case 'd':
|
case 'd':
|
||||||
flags |= CP_PRESERVE_SYMLINKS;
|
flags |= FILEUTILS_PRESERVE_SYMLINKS;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
flags |= CP_FORCE;
|
flags |= FILEUTILS_FORCE;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
flags |= CP_INTERACTIVE;
|
flags |= FILEUTILS_INTERACTIVE;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
flags |= CP_PRESERVE_STATUS;
|
flags |= FILEUTILS_PRESERVE_STATUS;
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
flags |= CP_RECUR;
|
flags |= FILEUTILS_RECUR;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
@ -73,9 +73,9 @@ extern int cp_main(int argc, char **argv)
|
|||||||
int source_exists = 1;
|
int source_exists = 1;
|
||||||
int dest_exists = 1;
|
int dest_exists = 1;
|
||||||
|
|
||||||
if (((flags & CP_PRESERVE_SYMLINKS) &&
|
if (((flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||||
lstat(argv[optind], &source_stat) < 0) ||
|
lstat(argv[optind], &source_stat) < 0) ||
|
||||||
(!(flags & CP_PRESERVE_SYMLINKS) &&
|
(!(flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||||
stat(argv[optind], &source_stat))) {
|
stat(argv[optind], &source_stat))) {
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
perror_msg_and_die("unable to stat `%s'", argv[optind]);
|
perror_msg_and_die("unable to stat `%s'", argv[optind]);
|
||||||
@ -93,7 +93,7 @@ extern int cp_main(int argc, char **argv)
|
|||||||
(!dest_exists || !S_ISDIR(dest_stat.st_mode))) ||
|
(!dest_exists || !S_ISDIR(dest_stat.st_mode))) ||
|
||||||
/* ...recursing, the first is a directory, and the
|
/* ...recursing, the first is a directory, and the
|
||||||
* second doesn't exist, then... */
|
* second doesn't exist, then... */
|
||||||
((flags & CP_RECUR) && S_ISDIR(source_stat.st_mode) &&
|
((flags & FILEUTILS_RECUR) && S_ISDIR(source_stat.st_mode) &&
|
||||||
!dest_exists)) {
|
!dest_exists)) {
|
||||||
/* ...do a simple copy. */
|
/* ...do a simple copy. */
|
||||||
if (copy_file(argv[optind], argv[optind + 1], flags) < 0)
|
if (copy_file(argv[optind], argv[optind + 1], flags) < 0)
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
static int flags = CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS;
|
static int flags;
|
||||||
|
|
||||||
static int remove_file(const char *path, struct stat *statbuf, void *junk)
|
static int remove_file(const char *path, struct stat *statbuf, void *junk)
|
||||||
{
|
{
|
||||||
@ -88,8 +88,8 @@ static int manual_rename(const char *source, const char *dest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_file(source, dest,
|
if (copy_file(source, dest, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS |
|
||||||
CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS) < 0)
|
FILEUTILS_PRESERVE_SYMLINKS) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file,
|
if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file,
|
||||||
@ -112,9 +112,9 @@ static int move_file(const char *source, const char *dest)
|
|||||||
dest_exists = 0;
|
dest_exists = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dest_exists && !(flags & CP_FORCE) &&
|
if (dest_exists && !(flags & FILEUTILS_FORCE) &&
|
||||||
((access(dest, W_OK) < 0 && isatty(0)) ||
|
((access(dest, W_OK) < 0 && isatty(0)) ||
|
||||||
(flags & CP_INTERACTIVE))) {
|
(flags & FILEUTILS_INTERACTIVE))) {
|
||||||
fprintf(stderr, "mv: overwrite `%s'? ", dest);
|
fprintf(stderr, "mv: overwrite `%s'? ", dest);
|
||||||
if (!ask_confirmation())
|
if (!ask_confirmation())
|
||||||
return 0;
|
return 0;
|
||||||
@ -140,12 +140,12 @@ extern int mv_main(int argc, char **argv)
|
|||||||
while ((opt = getopt(argc, argv, "fi")) != -1)
|
while ((opt = getopt(argc, argv, "fi")) != -1)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'f':
|
case 'f':
|
||||||
flags &= ~CP_INTERACTIVE;
|
flags &= ~FILEUTILS_INTERACTIVE;
|
||||||
flags |= CP_FORCE;
|
flags |= FILEUTILS_FORCE;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
flags &= ~CP_FORCE;
|
flags &= ~FILEUTILS_FORCE;
|
||||||
flags |= CP_INTERACTIVE;
|
flags |= FILEUTILS_INTERACTIVE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
|
18
cp.c
18
cp.c
@ -42,22 +42,22 @@ extern int cp_main(int argc, char **argv)
|
|||||||
while ((opt = getopt(argc, argv, "adfipR")) != -1)
|
while ((opt = getopt(argc, argv, "adfipR")) != -1)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
flags |= CP_PRESERVE_STATUS | CP_RECUR;
|
flags |= FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case 'd':
|
case 'd':
|
||||||
flags |= CP_PRESERVE_SYMLINKS;
|
flags |= FILEUTILS_PRESERVE_SYMLINKS;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
flags |= CP_FORCE;
|
flags |= FILEUTILS_FORCE;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
flags |= CP_INTERACTIVE;
|
flags |= FILEUTILS_INTERACTIVE;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
flags |= CP_PRESERVE_STATUS;
|
flags |= FILEUTILS_PRESERVE_STATUS;
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
flags |= CP_RECUR;
|
flags |= FILEUTILS_RECUR;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
@ -73,9 +73,9 @@ extern int cp_main(int argc, char **argv)
|
|||||||
int source_exists = 1;
|
int source_exists = 1;
|
||||||
int dest_exists = 1;
|
int dest_exists = 1;
|
||||||
|
|
||||||
if (((flags & CP_PRESERVE_SYMLINKS) &&
|
if (((flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||||
lstat(argv[optind], &source_stat) < 0) ||
|
lstat(argv[optind], &source_stat) < 0) ||
|
||||||
(!(flags & CP_PRESERVE_SYMLINKS) &&
|
(!(flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||||
stat(argv[optind], &source_stat))) {
|
stat(argv[optind], &source_stat))) {
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
perror_msg_and_die("unable to stat `%s'", argv[optind]);
|
perror_msg_and_die("unable to stat `%s'", argv[optind]);
|
||||||
@ -93,7 +93,7 @@ extern int cp_main(int argc, char **argv)
|
|||||||
(!dest_exists || !S_ISDIR(dest_stat.st_mode))) ||
|
(!dest_exists || !S_ISDIR(dest_stat.st_mode))) ||
|
||||||
/* ...recursing, the first is a directory, and the
|
/* ...recursing, the first is a directory, and the
|
||||||
* second doesn't exist, then... */
|
* second doesn't exist, then... */
|
||||||
((flags & CP_RECUR) && S_ISDIR(source_stat.st_mode) &&
|
((flags & FILEUTILS_RECUR) && S_ISDIR(source_stat.st_mode) &&
|
||||||
!dest_exists)) {
|
!dest_exists)) {
|
||||||
/* ...do a simple copy. */
|
/* ...do a simple copy. */
|
||||||
if (copy_file(argv[optind], argv[optind + 1], flags) < 0)
|
if (copy_file(argv[optind], argv[optind + 1], flags) < 0)
|
||||||
|
@ -255,11 +255,11 @@ extern int gz_open(FILE *compressed_file, int *pid);
|
|||||||
/* extern int convert(char *fn, int ConvType); */
|
/* extern int convert(char *fn, int ConvType); */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CP_PRESERVE_STATUS = 1,
|
FILEUTILS_PRESERVE_STATUS = 1,
|
||||||
CP_PRESERVE_SYMLINKS = 2,
|
FILEUTILS_PRESERVE_SYMLINKS = 2,
|
||||||
CP_RECUR = 4,
|
FILEUTILS_RECUR = 4,
|
||||||
CP_FORCE = 8,
|
FILEUTILS_FORCE = 8,
|
||||||
CP_INTERACTIVE = 16
|
FILEUTILS_INTERACTIVE = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char *applet_name;
|
extern const char *applet_name;
|
||||||
|
@ -39,8 +39,9 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
int dest_exists = 1;
|
int dest_exists = 1;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
if (((flags & CP_PRESERVE_SYMLINKS) && lstat(source, &source_stat) < 0) ||
|
if (((flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||||
(!(flags & CP_PRESERVE_SYMLINKS) &&
|
lstat(source, &source_stat) < 0) ||
|
||||||
|
(!(flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||||
stat(source, &source_stat) < 0)) {
|
stat(source, &source_stat) < 0)) {
|
||||||
perror_msg("%s", source);
|
perror_msg("%s", source);
|
||||||
return -1;
|
return -1;
|
||||||
@ -64,7 +65,7 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
|
|
||||||
if (!(flags & CP_RECUR)) {
|
if (!(flags & FILEUTILS_RECUR)) {
|
||||||
error_msg("%s: omitting directory", source);
|
error_msg("%s: omitting directory", source);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -80,7 +81,7 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
saved_umask = umask(0);
|
saved_umask = umask(0);
|
||||||
|
|
||||||
mode = source_stat.st_mode;
|
mode = source_stat.st_mode;
|
||||||
if (!(flags & CP_PRESERVE_STATUS))
|
if (!(flags & FILEUTILS_PRESERVE_STATUS))
|
||||||
mode = source_stat.st_mode & ~saved_umask;
|
mode = source_stat.st_mode & ~saved_umask;
|
||||||
mode |= S_IRWXU;
|
mode |= S_IRWXU;
|
||||||
|
|
||||||
@ -125,14 +126,14 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
FILE *sfp, *dfp;
|
FILE *sfp, *dfp;
|
||||||
|
|
||||||
if (dest_exists) {
|
if (dest_exists) {
|
||||||
if (flags & CP_INTERACTIVE) {
|
if (flags & FILEUTILS_INTERACTIVE) {
|
||||||
fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest);
|
fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest);
|
||||||
if (!ask_confirmation())
|
if (!ask_confirmation())
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dfp = fopen(dest, "w")) == NULL) {
|
if ((dfp = fopen(dest, "w")) == NULL) {
|
||||||
if (!(flags & CP_FORCE)) {
|
if (!(flags & FILEUTILS_FORCE)) {
|
||||||
perror_msg("unable to open `%s'", dest);
|
perror_msg("unable to open `%s'", dest);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -187,7 +188,7 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
saved_umask = umask(0);
|
saved_umask = umask(0);
|
||||||
|
|
||||||
mode = source_stat.st_mode;
|
mode = source_stat.st_mode;
|
||||||
if (!(flags & CP_PRESERVE_STATUS))
|
if (!(flags & FILEUTILS_PRESERVE_STATUS))
|
||||||
mode = source_stat.st_mode & ~saved_umask;
|
mode = source_stat.st_mode & ~saved_umask;
|
||||||
mode |= S_IRWXU;
|
mode |= S_IRWXU;
|
||||||
|
|
||||||
@ -213,7 +214,7 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||||
if (flags & CP_PRESERVE_STATUS)
|
if (flags & FILEUTILS_PRESERVE_STATUS)
|
||||||
if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
|
if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
|
||||||
perror_msg("unable to preserve ownership of `%s'", dest);
|
perror_msg("unable to preserve ownership of `%s'", dest);
|
||||||
#endif
|
#endif
|
||||||
@ -225,7 +226,7 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
if (flags & CP_PRESERVE_STATUS) {
|
if (flags & FILEUTILS_PRESERVE_STATUS) {
|
||||||
struct utimbuf times;
|
struct utimbuf times;
|
||||||
|
|
||||||
times.actime = source_stat.st_atime;
|
times.actime = source_stat.st_atime;
|
||||||
|
@ -255,11 +255,11 @@ extern int gz_open(FILE *compressed_file, int *pid);
|
|||||||
/* extern int convert(char *fn, int ConvType); */
|
/* extern int convert(char *fn, int ConvType); */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CP_PRESERVE_STATUS = 1,
|
FILEUTILS_PRESERVE_STATUS = 1,
|
||||||
CP_PRESERVE_SYMLINKS = 2,
|
FILEUTILS_PRESERVE_SYMLINKS = 2,
|
||||||
CP_RECUR = 4,
|
FILEUTILS_RECUR = 4,
|
||||||
CP_FORCE = 8,
|
FILEUTILS_FORCE = 8,
|
||||||
CP_INTERACTIVE = 16
|
FILEUTILS_INTERACTIVE = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char *applet_name;
|
extern const char *applet_name;
|
||||||
|
18
mv.c
18
mv.c
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
static int flags = CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS;
|
static int flags;
|
||||||
|
|
||||||
static int remove_file(const char *path, struct stat *statbuf, void *junk)
|
static int remove_file(const char *path, struct stat *statbuf, void *junk)
|
||||||
{
|
{
|
||||||
@ -88,8 +88,8 @@ static int manual_rename(const char *source, const char *dest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_file(source, dest,
|
if (copy_file(source, dest, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS |
|
||||||
CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS) < 0)
|
FILEUTILS_PRESERVE_SYMLINKS) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file,
|
if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file,
|
||||||
@ -112,9 +112,9 @@ static int move_file(const char *source, const char *dest)
|
|||||||
dest_exists = 0;
|
dest_exists = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dest_exists && !(flags & CP_FORCE) &&
|
if (dest_exists && !(flags & FILEUTILS_FORCE) &&
|
||||||
((access(dest, W_OK) < 0 && isatty(0)) ||
|
((access(dest, W_OK) < 0 && isatty(0)) ||
|
||||||
(flags & CP_INTERACTIVE))) {
|
(flags & FILEUTILS_INTERACTIVE))) {
|
||||||
fprintf(stderr, "mv: overwrite `%s'? ", dest);
|
fprintf(stderr, "mv: overwrite `%s'? ", dest);
|
||||||
if (!ask_confirmation())
|
if (!ask_confirmation())
|
||||||
return 0;
|
return 0;
|
||||||
@ -140,12 +140,12 @@ extern int mv_main(int argc, char **argv)
|
|||||||
while ((opt = getopt(argc, argv, "fi")) != -1)
|
while ((opt = getopt(argc, argv, "fi")) != -1)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'f':
|
case 'f':
|
||||||
flags &= ~CP_INTERACTIVE;
|
flags &= ~FILEUTILS_INTERACTIVE;
|
||||||
flags |= CP_FORCE;
|
flags |= FILEUTILS_FORCE;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
flags &= ~CP_FORCE;
|
flags &= ~FILEUTILS_FORCE;
|
||||||
flags |= CP_INTERACTIVE;
|
flags |= FILEUTILS_INTERACTIVE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
|
Loading…
Reference in New Issue
Block a user