Fix return values in rm(1) and mv(1)

by setting rm_status to 1 if removing 1 file in the list fails.
Extend this to mv_status in mv(1).
This commit is contained in:
FRIGN
2015-01-30 12:45:54 +01:00
parent a9c7d16cde
commit e60885699c
4 changed files with 26 additions and 20 deletions

35
mv.c
View File

@@ -8,7 +8,23 @@
#include "fs.h"
#include "util.h"
static int mv(const char *, const char *);
int mv_status = 0;
static int
mv(const char *s1, const char *s2)
{
if (rename(s1, s2) == 0)
return (mv_status = 0);
if (errno == EXDEV) {
cp_rflag = 1;
rm_rflag = 1;
cp(s1, s2);
rm(s1);
return (mv_status = cp_status || rm_status);
}
mv_status = 1;
return -1;
}
static void
usage(void)
@@ -36,20 +52,5 @@ main(int argc, char *argv[])
eprintf("%s: not a directory\n", argv[argc-1]);
enmasse(argc, &argv[0], mv);
return 0;
}
static int
mv(const char *s1, const char *s2)
{
if (rename(s1, s2) == 0)
return 0;
if (errno == EXDEV) {
cp_rflag = 1;
rm_rflag = 1;
cp(s1, s2);
rm(s1);
return 0;
}
return -1;
return mv_status;
}