1 package File::Tree::Snapshot;
6 our $VERSION = '0.000001';
7 $VERSION = eval $VERSION;
9 has storage_path => (is => 'ro', required => 1);
11 has allow_empty => (is => 'ro');
13 sub file { join '/', (shift)->storage_path, @_}
16 my ($self, $mode, $file, %opt) = @_;
17 $file = $self->file($file)
18 unless $opt{is_absolute};
19 $self->_mkpath(dirname $file)
21 open my $fh, $mode, $file
22 or die "Unable to write '$file': $!\n";
27 my ($self, $dir) = @_;
28 mkpath($dir, { error => \(my $err) });
30 warn "Error while attempting to create '$dir': $_\n"
31 for map { (values %$_) } @$err;
37 my ($self, $cmd) = @_;
38 system($cmd) and die "Error during ($cmd)\n";
43 my ($self, @cmd) = @_;
44 my $path = $self->storage_path;
45 #local $ENV{GIT_DIR} = "$path/.git";
47 sprintf q{cd %s && git %s},
55 my $path = $self->storage_path;
56 $self->_mkpath($path);
57 $self->_git_exec('init');
63 my $path = $self->storage_path;
64 my @changes = `cd $path && git diff --name-only --cached`;
65 return scalar @changes;
70 $self->_git_exec('add .');
71 unless ($self->_has_changes) {
75 $self->_git_exec('commit',
77 ($self->allow_empty ? '--allow-empty' : ()),
78 '-m' => sprintf('"Updated on %s"', scalar localtime),
85 $self->_git_exec('add .');
86 $self->_git_exec('checkout -f');
92 return -e join '/', $self->storage_path, '.git';
96 my ($self, $ext, @path) = @_;
97 my $root = $self->file(@path);
98 my @files = `find $root -name '*.$ext' -type f`;