mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-29 14:16:31 +00:00
package/makedevs: add recursive option
This patch adds the option to change owner/permission of a directory recursively. [Thomas: s/folder/directory/, as suggested by Yann.] Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com> Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
This commit is contained in:
parent
5e9766ed67
commit
410f9b6013
@ -34,8 +34,12 @@
|
|||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
#include <sys/sysmacros.h> /* major() and minor() */
|
#include <sys/sysmacros.h> /* major() and minor() */
|
||||||
#endif
|
#endif
|
||||||
|
#include <ftw.h>
|
||||||
|
|
||||||
const char *bb_applet_name;
|
const char *bb_applet_name;
|
||||||
|
uid_t recursive_uid;
|
||||||
|
gid_t recursive_gid;
|
||||||
|
unsigned int recursive_mode;
|
||||||
|
|
||||||
void bb_verror_msg(const char *s, va_list p)
|
void bb_verror_msg(const char *s, va_list p)
|
||||||
{
|
{
|
||||||
@ -332,6 +336,7 @@ void bb_show_usage(void)
|
|||||||
fprintf(stderr, "Where name is the file name, type can be one of:\n");
|
fprintf(stderr, "Where name is the file name, type can be one of:\n");
|
||||||
fprintf(stderr, " f A regular file\n");
|
fprintf(stderr, " f A regular file\n");
|
||||||
fprintf(stderr, " d Directory\n");
|
fprintf(stderr, " d Directory\n");
|
||||||
|
fprintf(stderr, " r Directory recursively\n");
|
||||||
fprintf(stderr, " c Character special device file\n");
|
fprintf(stderr, " c Character special device file\n");
|
||||||
fprintf(stderr, " b Block special device file\n");
|
fprintf(stderr, " b Block special device file\n");
|
||||||
fprintf(stderr, " p Fifo (named pipe)\n");
|
fprintf(stderr, " p Fifo (named pipe)\n");
|
||||||
@ -364,6 +369,23 @@ void bb_show_usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bb_recursive(const char *fpath, const struct stat *sb,
|
||||||
|
int tflag, struct FTW *ftwbuf){
|
||||||
|
|
||||||
|
if (chown(fpath, recursive_uid, recursive_gid) == -1) {
|
||||||
|
bb_perror_msg("chown failed for %s", fpath);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (recursive_mode != -1) {
|
||||||
|
if (chmod(fpath, recursive_mode) < 0) {
|
||||||
|
bb_perror_msg("chmod failed for %s", fpath);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
@ -474,6 +496,15 @@ int main(int argc, char **argv)
|
|||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
|
} else if (type == 'r') {
|
||||||
|
recursive_uid = uid;
|
||||||
|
recursive_gid = gid;
|
||||||
|
recursive_mode = mode;
|
||||||
|
if (nftw(full_name, bb_recursive, 20, FTW_MOUNT | FTW_PHYS) < 0) {
|
||||||
|
bb_perror_msg("line %d: recursive failed for %s", linenum, full_name);
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
dev_t rdev;
|
dev_t rdev;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user