1 package CloudStore::JSON;
11 my ( $dir, $json ) = @_;
12 warn "### VFS make_dir $dir\n";
13 File::Path::make_path($dir);
14 $dir =~ s{/([^/]+)/?$}{/.$1};
15 File::Slurp::write_file $dir, $json if $json;
19 warn "### VFS remove_dir $_[0]\n";
20 File::Path::remove_tree(@_);
24 warn "### VFS unlink $_[0]\n";
29 warn "### VFS ", -e $_[0] ? 'modify' : 'write', "_file $_[0]\n";
30 File::Slurp::write_file(@_);
35 warn "### VFS read_file $path\n";
36 $path =~ s{/([^/]+)/?$}{/.$1} if -d $path;
37 File::Slurp::read_file($path);
42 my $json = encode_json $data;
44 my $path = "users/$data->{login}/json/$data->{file}";
46 if ( $data->{itemize} =~ m/^[c>]([fd])/ ) { # received change/create
50 if ( $path =~ m{^(.+)/[^/]+$} ) { # have dir
51 make_dir $1, $json if ! -e $1;
53 write_file $path, $json;
54 } elsif ( $type eq 'd' ) {
55 make_dir $path, $json;
57 die "unknown type $type";
59 } elsif ( $data->{itemize} =~ m/\*deleting/ ) {
62 } elsif ( -f $path ) {
65 warn "ignored delete $path";
73 $path =~ s{/blob/}{/json/};
74 return decode_json read_file $path;