Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 86 lines (62 sloc) 1.703 kb
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
1 #!/usr/bin/perl
2 #
3 # compact -- compact your already-expired MV session database
4 #
5 # Bugs: uses only the default session lock and file names
6 #
7
8 $USAGE = <<EOF;
9 usage: compact.pl [catalog-directory]
10
11 Set to your software and catalog directory
12 or pass it a directory name
13 EOF
14
15 my $Catdir = shift || die "$USAGE\n";
16
17 # I usually do
18 use strict;
19
20 my $type; # GDBM_File or DB_File
21 my $flags; # How to open file
22 my $ext; # File extension
23
24 # Uncomment for Berkeley
25 BEGIN {
26 DBCHECK: {
27 eval {
28 die if $ENV{MINIVEND_DBFILE};
29 require GDBM_File;
30 import GDBM_File;
31 $type = 'GDBM_File';
32 $flags = &GDBM_WRCREAT;
33 $ext = '.gdbm';
34 };
35
36 last DBCHECK unless $@;
37
38 eval {
39 require DB_File;
40 import DB_File;
41 $type = 'DB_File';
42 $flags = &O_RDWR | &O_CREAT;
43 $ext = '.db';
44 };
45
46 last DBCHECK unless $@;
47
48 die "You don't need this script, not GDBM_File or DB_File.\n";
49
50 }
51 }
52
53 use Fcntl qw/:flock/;
54
55 my %session1;
56 my %session2;
57 my ($k, $v);
58
59 my $file1 = "$Catdir/session$ext";
60 my $file2 = "$Catdir/new_session$ext";
61
62 open(LOCK, "+<$Catdir/etc/session.lock")
63 or open(LOCK, ">>$Catdir/etc/session.lock")
64 or die "open lockfile: $!\n";
65
66 flock(LOCK, LOCK_EX)
67 or die "lock: $!\n";
68
69 tie(%session1, $type, $file1, $flags, 0777)
70 or die "tie $file1: $!\n";
71
72 unlink "$Catdir/new_session$ext";
73
74 tie(%session2, $type, $file2, $flags, 0777)
75 or die "tie $file2: $!\n";
76
77 while( ($k, $v) = each %session1) {
78 $session2{$k} = $v;
79 }
80
81 untie %session1 or die "untie: $!\n";
82 untie %session2 or die "untie: $!\n";
83
84 rename $file2, $file1 or die "rename $file1 to $file2: $!\n";
85
Something went wrong with that request. Please try again.