Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v2 1/2] package/makedevs: add recursive option
Date: Sat, 11 Apr 2015 17:07:00 +0200	[thread overview]
Message-ID: <20150411150659.GH4221@free.fr> (raw)
In-Reply-To: <1428759632-17060-2-git-send-email-angelo.compagnucci@gmail.com>

Angelo, All,

On 2015-04-11 15:40 +0200, Angelo Compagnucci spake thusly:
> This patch adds the option to change owner/permission
> of a folder recursively.

In *nix terminology, we usually refer to a 'directory' not a 'folder'.
'Folder' is a Windows-ism. ;-)

> 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>

Tested with a simple dirtectory tree, and manually running through
fakeroot that saved its internal DB, then manually inspected the DB
dump to contain what was expected.

Thanks! :-)

Regards,
Yann E. MORIN.

> ---
> Changelog:
> 
> v1 -> v2:
>   - Code refactoring to avoid nested functions as suggested
>     by Peter Korsgaard
> 
>  package/makedevs/makedevs.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/package/makedevs/makedevs.c b/package/makedevs/makedevs.c
> index ab90b93..ee0f9fb 100644
> --- a/package/makedevs/makedevs.c
> +++ b/package/makedevs/makedevs.c
> @@ -34,8 +34,12 @@
>  #ifndef __APPLE__
>  #include <sys/sysmacros.h>     /* major() and minor() */
>  #endif
> +#include <ftw.h>
>  
>  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)
>  {
> @@ -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, "      f       A regular file\n");
>  	fprintf(stderr, "      d       Directory\n");
> +	fprintf(stderr, "      r       Directory recursively\n");
>  	fprintf(stderr, "      c       Character special device file\n");
>  	fprintf(stderr, "      b       Block special device file\n");
>  	fprintf(stderr, "      p       Fifo (named pipe)\n");
> @@ -364,6 +369,23 @@ void bb_show_usage(void)
>  	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 opt;
> @@ -474,6 +496,15 @@ int main(int argc, char **argv)
>  				ret = EXIT_FAILURE;
>  				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
>  		{
>  			dev_t rdev;
> -- 
> 1.9.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

  reply	other threads:[~2015-04-11 15:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-11 13:40 [Buildroot] [PATCH v2 0/2] Makedevs: add recursive option Angelo Compagnucci
2015-04-11 13:40 ` [Buildroot] [PATCH v2 1/2] package/makedevs: " Angelo Compagnucci
2015-04-11 15:07   ` Yann E. MORIN [this message]
2015-04-11 13:40 ` [Buildroot] [PATCH v2 2/2] docs/manual: documentation for recursive makedevs syntax Angelo Compagnucci
2015-04-11 15:08   ` Yann E. MORIN
2015-04-11 16:04 ` [Buildroot] [PATCH v2 0/2] Makedevs: add recursive option Thomas Petazzoni
2015-04-11 16:56   ` Angelo Compagnucci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150411150659.GH4221@free.fr \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox