10 our @EXPORT = qw(scrypt jailed_file
12 filedb_atomic_append filedb_atomic_edit
13 valid_email valid_repo_url valid_web_url);
19 crypt($pwd, join ('', ('.', '/', 2..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]));
24 $Girocco::Config
::chroot."/$filename";
33 use Fcntl
qw(O_WRONLY O_CREAT O_EXCL);
35 my $handle = new IO
::Handle
;
37 unless (sysopen($handle, $path, O_WRONLY
|O_CREAT
|O_EXCL
)) {
39 while (not sysopen($handle, $path, O_WRONLY
|O_CREAT
|O_EXCL
)) {
40 ($! == EEXIST
) or die "$path open failed: $!";
41 ($cnt++ < 16) or die "$path open failed: cannot open lockfile";
45 # XXX: filedb-specific
46 chmod 0664, $path or die "$path g+w failed: $!";
54 rename "$path.lock", $path or die "$path unlock failed: $!";
57 sub filedb_atomic_append
{
58 my ($file, $line) = @_;
61 open my $src, $file or die "$file open for reading failed: $!";
62 my $dst = lock_file
($file);
65 my $aid = (split /:/)[2];
66 $id = $aid + 1 if ($aid >= $id);
68 print $dst $_ or die "$file(l) write failed: $!";
72 print $dst "$line\n" or die "$file(l) write failed: $!";
74 close $dst or die "$file(l) close failed: $!";
82 sub filedb_atomic_edit
{
85 open my $src, $file or die "$file open for reading failed: $!";
86 my $dst = lock_file
($file);
89 print $dst $fn->($_) or die "$file(l) write failed: $!";
92 close $dst or die "$file(l) close failed: $!";
100 /^[a-zA-Z0-9+._-]+@[a-zA-Z0-9-.]+$/;
104 /^http:\/\
/[a-zA-Z0-9-.]+(\/[_\
%a-zA
-Z0
-9.\
/~-]*)?(#[a-zA-Z0-9._-]+)?$/;
108 /^http:\/\
/[a-zA-Z0-9-.]+(\/[_\
%a-zA
-Z0
-9.\
/~-]*)?$/ or
109 /^git:\/\
/[a-zA-Z0-9-.]+(\/[_\
%a-zA
-Z0
-9.\
/~-]*)?$/;