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]));
26 $Girocco::Config
::chroot."/$filename";
35 use Fcntl
qw(O_WRONLY O_CREAT O_EXCL);
37 my $handle = new IO
::Handle
;
39 unless (sysopen($handle, $path, O_WRONLY
|O_CREAT
|O_EXCL
)) {
41 while (not sysopen($handle, $path, O_WRONLY
|O_CREAT
|O_EXCL
)) {
42 ($! == EEXIST
) or die "$path open failed: $!";
43 ($cnt++ < 16) or die "$path open failed: cannot open lockfile";
47 # XXX: filedb-specific
48 chmod 0664, $path or die "$path g+w failed: $!";
56 rename "$path.lock", $path or die "$path unlock failed: $!";
59 sub filedb_atomic_append
{
60 my ($file, $line) = @_;
63 open my $src, $file or die "$file open for reading failed: $!";
64 my $dst = lock_file
($file);
67 my $aid = (split /:/)[2];
68 $id = $aid + 1 if ($aid >= $id);
70 print $dst $_ or die "$file(l) write failed: $!";
74 print $dst "$line\n" or die "$file(l) write failed: $!";
76 close $dst or die "$file(l) close failed: $!";
84 sub filedb_atomic_edit
{
87 open my $src, $file or die "$file open for reading failed: $!";
88 my $dst = lock_file
($file);
91 print $dst $fn->($_) or die "$file(l) write failed: $!";
94 close $dst or die "$file(l) close failed: $!";
102 /^[a-zA-Z0-9+._-]+@[a-zA-Z0-9-.]+$/;
104 sub valid_email_multi
{
106 # More relaxed, we just want to avoid too dangerous characters.
107 /^[a-zA-Z0-9+._, @-]+$/;
111 /^https?:\/\
/[a-zA-Z0-9-.:]+(\/[_\
%a-zA
-Z0
-9.\
/~:?&=;-]*)?(#[a-zA-Z0-9._-]+)?$/;
115 /^(https?|git|svn(\+http)?|svn(\+https)?|darcs|bzr):\/\
/[a-zA-Z0-9-.:]+(\/[_\
%a-zA
-Z0
-9.\
/~-]*)?$/;