diff options
author | Andinus <andinus@nand.sh> | 2020-06-10 21:46:13 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-06-10 21:46:13 +0530 |
commit | e876bc2fc08e44f3ea94f5a0954acefefda774b6 (patch) | |
tree | 8986087054a5141f9adcbb4e27992a36bcba2a2e | |
parent | 23062e4c73a6584dbb72c393ce45fa7fdab4a1e1 (diff) | |
download | ara-e876bc2fc08e44f3ea94f5a0954acefefda774b6.tar.gz |
Save $file in cache directory
This includes unix specific code & should be mentioned in README.
-rwxr-xr-x | ara.pl | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ara.pl b/ara.pl index d458ff4..64210e7 100755 --- a/ara.pl +++ b/ara.pl @@ -41,29 +41,31 @@ sub HelpMessage { die "Can't use --local and --latest together\n" if $use_local_file and $get_latest ; +my $cache_dir = $ENV{XDG_CACHE_HOME} || "$ENV{HOME}/.cache"; + # %unveil contains list of paths to unveil with their permissions. my %unveil = ( "/usr" => "rx", "/var" => "rx", "/etc" => "rx", "/dev" => "rx", - "/tmp" => "rwc", - "/dev/null" => "rw", + # Unveil the whole cache directory because HTTP::Tiny fetches file + # like ara.jsonXXXXXXXXXX where each 'X' is a random number. + $cache_dir => "rwc", ); # Unveil each path from %unveil. keys %unveil; - # We use sort because otherwise keys is random order everytime. foreach my $path ( sort keys %unveil ) { unveil( $path, $unveil{$path} ) or die "Unable to unveil: $!"; } -my $file = '/tmp/data.json'; +my $file = "$cache_dir/ara.json"; my $file_ctime; -# If $file exists then get mtime. +# If $file exists then get ctime. if ( -e $file ) { my $file_stat = path($file)->stat; $file_ctime = Time::Moment->from_epoch( $file_stat->ctime ); |