10 our @EXPORT = qw(scrypt jailed_file
12 filedb_atomic_append filedb_atomic_edit
13 valid_email valid_email_multi
14 valid_repo_url valid_web_url);
20 crypt($pwd, join ('', ('.', '/', 2..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]));
25 $Girocco::Config
::chroot."/$filename";
34 use Fcntl
qw(O_WRONLY O_CREAT O_EXCL);
36 my $handle = new IO
::Handle
;
38 unless (sysopen($handle, $path, O_WRONLY
|O_CREAT
|O_EXCL
)) {
40 while (not sysopen($handle, $path, O_WRONLY
|O_CREAT
|O_EXCL
)) {
41 ($! == EEXIST
) or die "$path open failed: $!";
42 ($cnt++ < 16) or die "$path open failed: cannot open lockfile";
46 # XXX: filedb-specific
47 chmod 0664, $path or die "$path g+w failed: $!";
55 rename "$path.lock", $path or die "$path unlock failed: $!";
58 sub filedb_atomic_append
{
59 my ($file, $line) = @_;
62 open my $src, $file or die "$file open for reading failed: $!";
63 my $dst = lock_file
($file);
66 my $aid = (split /:/)[2];
67 $id = $aid + 1 if ($aid >= $id);
69 print $dst $_ or die "$file(l) write failed: $!";
73 print $dst "$line\n" or die "$file(l) write failed: $!";
75 close $dst or die "$file(l) close failed: $!";
83 sub filedb_atomic_edit
{
86 open my $src, $file or die "$file open for reading failed: $!";
87 my $dst = lock_file
($file);
90 print $dst $fn->($_) or die "$file(l) write failed: $!";
93 close $dst or die "$file(l) close failed: $!";
101 /^[a-zA-Z0-9+._-]+@[a-zA-Z0-9-.]+$/;
103 sub valid_email_multi
{
105 # More relaxed, we just want to avoid too dangerous characters.
106 /^[a-zA-Z0-9+._, @-]+$/;
110 /^http:\/\
/[a-zA-Z0-9-.]+(\/[_\
%a-zA
-Z0
-9.\
/~:-]*)?(#[a-zA-Z0-9._-]+)?$/;
114 /^(http|git|svn|darcs|bzr):\/\
/[a-zA-Z0-9-.]+(\/[_\
%a-zA
-Z0
-9.\
/~-]*)?$/;