Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed c16924c

Added "user" and "group".

  • Participants
  • Parent commits 108a3de

Comments (0)

Files changed (2)

File File-Dir-Dumper/lib/File/Dir/Dumper/Scanner.pm

 __PACKAGE__->mk_accessors(
     qw(
     _file_find
+    _group_cache
     _last_result
     _queue
     _reached_end
     _result
+    _user_cache
     )
 );
 
     $self->_queue([]);
 
     $self->_add({ type => "header", dir_to_dump => $dir_to_dump, stream_type => "Directory Dump"});
+
+    $self->_user_cache({});
+    $self->_group_cache({});
     
     return;
 }
     return $depth;
 }
 
+sub _get_user_name
+{
+    my $self = shift;
+    my $uid = shift;
+
+    if (!exists($self->_user_cache()->{$uid}))
+    {
+        $self->_user_cache()->{$uid} = scalar(getpwuid($uid));
+    }
+
+    return $self->_user_cache()->{$uid};
+}
+
+sub _get_group_name
+{
+    my $self = shift;
+    my $gid = shift;
+
+    if (!exists($self->_group_cache()->{$gid}))
+    {
+        $self->_group_cache()->{$gid} = scalar(getgrgid($gid));
+    }
+
+    return $self->_group_cache()->{$gid};
+}
+
 sub _calc_file_or_dir_token
 {
     my $self = shift;
         depth => scalar(@{$result->full_components()}),
         perms => sprintf("%04o", ($stat[2]&07777)),
         mtime => strftime("%Y-%m-%dT%H:%M:%S", localtime($stat[9])),
+        user => $self->_get_user_name($stat[4]),
+        group => $self->_get_group_name($stat[5]),
         ($result->is_dir()
             ? (type => "dir",)
             : (type => "file", size => $stat[7],)

File File-Dir-Dumper/t/dumper.t

 use strict;
 use warnings;
 
-use Test::More tests => 32;
+use Test::More tests => 36;
 
 use POSIX qw(mktime strftime);
 use File::Path;
+use English;
 
 use File::Spec;
 use lib File::Spec->catdir(File::Spec->curdir(), "t", "lib");
     );
 
     # TEST
+    is ($token->{user},
+        scalar(getpwuid($UID)),
+        "user is OK."
+    );
+
+    # TEST
+    is ($token->{group},
+        scalar(getgrgid($GID)),
+        "group is OK."
+    );
+    
+
+    # TEST
     is ($token->{depth}, 1, "Token depth is 1");
 
     $token = $scanner->fetch();
         "perms are OK."
     );
 
+    # TEST
+    is ($token->{user},
+        scalar(getpwuid($UID)),
+        "user is OK."
+    );
+
+    # TEST
+    is ($token->{group},
+        scalar(getgrgid($GID)),
+        "group is OK."
+    );
 
     $token = $scanner->fetch();