/[pub]/suikawiki/script/lib/SuikaWiki/DB/FileSystem/LeafFile.pm
Suika

Contents of /suikawiki/script/lib/SuikaWiki/DB/FileSystem/LeafFile.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Mon Nov 8 09:57:49 2004 UTC (21 years, 8 months ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect, HEAD
Branch point for: helowiki, helowiki-2005
Changes since 1.3: +8 -2 lines
Committed

1
2 =head1 NAME
3
4 SuikaWiki::DB::FileSystem::LeafFile - SuikaWiki Directory-Structured Simple Database
5
6 =head1 SYNOPSIS
7
8 require SuikaWiki::DB::FileSystem::LeafFile;
9 my $db = SuikaWiki::DB::FileSystem::LeafFile->new
10 (base_directory => $path_to_db,
11 directory_suffix => '.ns',
12 file_suffix => '.txt',
13 -lock => { ..lock property.. });
14
15 =head1 DESCRIPTION
16
17 C<SuikaWiki::DB::FileSystem::LeafFile> provides simple database
18 which maps namespaces to filesystem directories and keys to files.
19 Directories and files names are encoded by base 16 so that user
20 does not need to make key names filesystem safe (but file names is
21 to be unreadable by human).
22
23 This module is part of SuikaWiki.
24
25 =cut
26
27 package SuikaWiki::DB::FileSystem::LeafFile;
28 use strict;
29 our $VERSION=do{my @r=(q$Revision: 1.3 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
30 require SuikaWiki::DB::FileSystem::Base;
31 push our @ISA, 'SuikaWiki::DB::FileSystem::Base';
32 use IO::File;
33
34 sub get ($$$;%) {
35 my ($self, $prop, $key, %opt) = @_;
36 report SuikaWiki::DB::Util::Error
37 -type => 'KEY_INVALID_NAME', key => $key,
38 -object => $self, method => 'get'
39 unless $opt{no_key_check} or
40 $self->__check_key (key => $key);
41
42 unless ($self->{opened}->{$prop}) {
43 local $Error::Depth = $Error::Depth + 1;
44 $self->open_prop (prop => $prop);
45 }
46
47 my $path = $self->__key2filepath (key => $key);
48
49 if (-e $path) {
50 my $file = new IO::File $path, '<'
51 or report SuikaWiki::DB::Util::Error
52 -type => 'FILE_READ_FAILURE',
53 -object => $self, method => 'get',
54 file => $path, msg => $!;
55 binmode $file;
56 local $/ = undef;
57 return scalar <$file>;
58 } else {
59 return undef;
60 }
61 }
62
63 sub set ($$$$;%) {
64 my ($self, $prop, $key, $val, %opt) = @_;
65 report SuikaWiki::DB::Util::Error
66 -type => 'KEY_INVALID_NAME', key => $key,
67 -object => $self, method => 'set'
68 unless $opt{no_key_check} or
69 $self->__check_key (key => $key);
70
71 unless ($self->{opened}->{$prop}) {
72 local $Error::Depth = $Error::Depth + 1;
73 $self->open_prop (prop => $prop);
74 }
75
76 if ($self->{lock} and not $self->{lock}->writable) {
77 report SuikaWiki::DB::Util::Error
78 -type => 'KEY_SAVE_LOCKED',
79 -object => $self, method => 'set',
80 key => $key,
81 prop => $prop;
82 return 0;
83 }
84
85 $self->__make_directory (directory => $self->__key2dirpath (fullkey => $key));
86 my $path = $self->__key2filepath (key => $key);
87 my $file = new IO::File $path, '>'
88 or report SuikaWiki::DB::Util::Error
89 -type => 'FILE_WRITE_FAILURE',
90 -object => $self, method => 'set',
91 file => $path, msg => $!;
92 binmode $file;
93 print $file $val;
94 close $file;
95 1;
96 }
97
98 sub _content_id ($$$;%) {
99 my ($self, $prop, $key, %opt) = @_;
100 require Digest::SHA1;
101 Digest::SHA1::sha1 ($self->get ($prop, $key, %opt));
102 }
103
104 =head1 SEE ALSO
105
106 C<SuikaWiki::DB::FileSystem::Base>.
107
108 =head1 LICENSE
109
110 Copyright 2004 Wakaba <w@suika.fam.cx>. All rights reserved.
111
112 This program is free software; you can redistribute it and/or
113 modify it under the same terms as Perl itself.
114
115 =cut
116
117 1; # $Date: 2004/06/03 06:38:48 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24