Subject: Developers of Sympa
List archive
Re: [sympa-developpers] [sympa-commits] sympa[10581] trunk: [dev] use 0777 as default mode, to fix usage with undefine value
- From: IKEDA Soji <address@concealed>
- To: address@concealed
- Subject: Re: [sympa-developpers] [sympa-commits] sympa[10581] trunk: [dev] use 0777 as default mode, to fix usage with undefine value
- Date: Tue, 3 Jun 2014 21:41:26 +0900
Hi,
Current umask would be respected. Sympa sets it using Site->umask.
It is irritated for me that mkdir_all() ignores umask, because
some spools etc. expose their content to all the users.
Regards,
--- Soji
On Wed, 7 May 2014 19:34:03 +0200 (CEST)
address@concealed wrote:
> sympa[10581] trunk: [dev] use 0777 as default mode, to fix usage with
> undefine value
> Revision 10581 Author rousse Date 2014-05-07 19:34:02 +0200 (mer. 07 mai
> 2014)
> Log Message[dev] use 0777 as default mode, to fix usage with undefine value
>
> Additionaly:
> - return immediatly if parent directory creation fails
> - change umask only when needed
> - use explicit functions call syntax
> - update expected test results
> Modified Paths
> trunk/src/lib/Sympa/Tools/File.pm
> trunk/t/tools_file.t
> Diff
> Modified: trunk/src/lib/Sympa/Tools/File.pm (10580 => 10581)
> --- trunk/src/lib/Sympa/Tools/File.pm 2014-05-07 15:47:53 UTC (rev 10580)
> +++ trunk/src/lib/Sympa/Tools/File.pm 2014-05-07 17:34:02 UTC (rev 10581)
> @@ -167,36 +167,31 @@
>
> sub mkdir_all {
> my ($path, $mode) = @_;
> - my $status = 1;
>
> - ## Change umask to fully apply modes of mkdir()
> - my $saved_mask = umask;
> - umask 0000;
> + return unless $path;
> + return 1 if -d $path;
>
> - return undef if ($path eq '');
> - return 1 if (-d $path);
> + $mode = 0777 if !$mode;
>
> ## Compute parent path
> - my @token = split /\//, $path;
> + my @token = split(/\//, $path);
> pop @token;
> - my $parent_path = join '/', @token;
> + my $parent_path = join('/', @token);
>
> unless (-d $parent_path) {
> - unless (mkdir_all($parent_path, $mode)) {
> - $status = undef;
> - }
> + my $result = mkdir_all($parent_path, $mode);
> + return unless $result;
> }
> +
> + # Change umask to fully apply modes of mkdir()
> + my $saved_mask = umask();
> + umask(0000);
>
> - if (defined $status) { ## Don't try if parent dir could not be
> created
> - unless (mkdir($path, $mode)) {
> - $status = undef;
> - }
> - }
> + my $result = mkdir($path, $mode);
>
> - ## Restore umask
> - umask $saved_mask;
> + umask($saved_mask);
>
> - return $status;
> + return $result;
> }
>
> =item shift_file($file, $count)
> Modified: trunk/t/tools_file.t (10580 => 10581)
> --- trunk/t/tools_file.t 2014-05-07 15:47:53 UTC (rev 10580)
> +++ trunk/t/tools_file.t 2014-05-07 17:34:02 UTC (rev 10581)
> @@ -18,7 +18,7 @@
>
> use Sympa::Tools::File;
>
> -plan tests => 24;
> +plan tests => 26;
>
> my $user = getpwuid($UID);
> my $group = getgrgid($GID);
> @@ -116,15 +116,17 @@
>
> $dir = File::Temp->newdir();
> Sympa::Tools::File::mkdir_all($dir . '/foo/bar/baz');
> -ok(!-d "$dir/foo", 'mkdir_all first element, no mode');
> -ok(!-d "$dir/foo/bar", 'mkdir_all second element, no mode');
> +ok(-d "$dir/foo", 'mkdir_all first directory presence');
> +is(get_perms("$dir/foo"), "0777", "mkdir_all first directory expected
> mode");
> +ok(-d "$dir/foo/bar", 'mkdir_all second directory presence');
> +is(get_perms("$dir/foo/bar"), "0777", "mkdir_all second directory expected
> mode");
>
> $dir = File::Temp->newdir();
> -Sympa::Tools::File::mkdir_all($dir . '/foo/bar/baz', 0777);
> -ok(-d "$dir/foo", 'mkdir_all first element');
> -ok(-d "$dir/foo/bar", 'mkdir_all second element');
> -is(get_perms("$dir/foo"), "0777", "first element, expected mode");
> -is(get_perms("$dir/foo/bar"), "0777", "second element, expected mode");
> +Sympa::Tools::File::mkdir_all($dir . '/foo/bar/baz', 0755);
> +ok(-d "$dir/foo", 'mkdir_all first directory presence');
> +is(get_perms("$dir/foo"), "0755", "mkdir_all first directory expected
> mode");
> +ok(-d "$dir/foo/bar", 'mkdir_all second directory presence');
> +is(get_perms("$dir/foo/bar"), "0755", "mkdir_all second directory expected
> mode");
>
> sub touch {
> my ($file) = @_;
--
株式会社 コンバージョン セキュリティ&OSSソリューション部 池田荘児
〒231-0004 神奈川県横浜市中区元浜町3-21-2 ヘリオス関内ビル7F
e-mail address@concealed TEL 045-640-3550
http://www.conversion.co.jp/
- Re: [sympa-developpers] [sympa-commits] sympa[10581] trunk: [dev] use 0777 as default mode, to fix usage with undefine value, IKEDA Soji, 06/03/2014
Archive powered by MHonArc 2.6.19+.