* Don't autovifivy @fields array entries.
[interchange.git] / code / UI_Tag / file_info.coretag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: file_info.coretag,v 1.4 2007-03-30 23:40:54 pajamian Exp $
9
10 UserTag file-info Order       name
11 UserTag file-info attrAlias   file name
12 UserTag file-info addAttr
13 UserTag file-info Version     $Revision: 1.4 $
14 UserTag file-info Routine     <<EOR
15 sub {
16         my ($fn, $opt) = @_;
17         if($opt->{server}) {
18                 $fn = "$Global::VendRoot/$fn"
19         }
20         elsif($opt->{conf}) {
21                 $fn = "$Global::ConfDir/$fn"
22         }
23         elsif($opt->{run}) {
24                 $fn = "$Global::RunDir/$fn"
25         }
26         my @stat = stat($fn);
27         my %info;
28         my @ary;
29         my $size  = $stat[7] < 1024
30                                          ? $stat[7]
31                                          : ( $stat[7] < 1024 * 1024
32                                                 ? sprintf ("%.2fK", $stat[7] / 1024)
33                                                 : sprintf ("%.2fM", $stat[7] / 1024 / 1024)
34                                                 );
35         if($opt->{flags}) {
36                 $opt->{flags} =~ s/\W//g;
37                 my @flags = split //, $opt->{flags};
38                 for(@flags) {
39                         s/(.)/"-$1 _"/ee;
40                 }
41                 return join "\t", @flags;
42         }
43         if($opt->{size}) {
44                 return $stat[7];
45         }
46         if($opt->{time}) {
47                 return $stat[9];
48         }
49         if($opt->{date}) {
50                 return $Tag->time($Scratch->{mv_locale},{time => $stat[9], gmt => $opt->{gmt}},'%c');
51         }
52         $opt->{fmt} = '%f bytes, last modified %Y-%m-%d %H:%M:%S'
53                 if ! $opt->{fmt};
54         $opt->{fmt} =~ s/%f/$size/g;
55     $Tag->time($Scratch->{mv_locale},{time => $stat[9], gmt => $opt->{gmt}},$opt->{fmt});
56 }
57 EOR