]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/upgrade-1.0-store.pl
Bug 5428: Warn if pkg-config is not found (#1902)
[thirdparty/squid.git] / scripts / upgrade-1.0-store.pl
CommitLineData
d36b569d 1#!/usr/local/bin/perl
a151895d 2#
b8ae064d 3## Copyright (C) 1996-2023 The Squid Software Foundation and contributors
a151895d
AJ
4##
5## Squid software is distributed under GPLv2+ license and includes
6## contributions from numerous individuals and organizations.
7## Please see the COPYING and CONTRIBUTORS files for details.
8##
d36b569d 9
d36b569d 10select(STDERR); $|=1;
11select(STDOUT); $|=1;
12
5e5ff464 13$USAGE="Usage: $0 swaplog cachedir1 cachedir2 ...\n";
d36b569d 14
15$dry_run = 0;
16
17$swaplog = shift || die $USAGE;
18(@cachedirs = @ARGV) || die $USAGE;
19$ncache_dirs = $#cachedirs + 1;
20
21$OLD_SWAP_DIRECTORIES = 100;
22$NEW_SWAP_DIRECTORIES_L1 = 16;
23$NEW_SWAP_DIRECTORIES_L2 = 256;
24
47f28373 25$EEXIST = 17; # check your /usr/include/errno.h
d36b569d 26
27print <<EOF;
28This script converts Squid 1.0 cache directories to the Squid 1.1
29format. The first step is to create the new directory structure.
30The second step is to link the swapfiles from the old directories
31into the new directories. After this script runs you must manually
32remove the old directories.
33
34Filesystem operations are slow, so this script may take a while.
35Your cache should NOT be running while this script runs.
36
37Are you ready to proceed?
38EOF
39
40$ans = <STDIN>;
41
42exit(1) unless ($ans =~ /^y$/ || $ans =~ /^yes$/);
43
44# make new directories
45foreach $c (@cachedirs) {
47f28373
FC
46 $cn = "$c.new";
47 &my_mkdir ($cn);
48 foreach $d1 (0..($NEW_SWAP_DIRECTORIES_L1-1)) {
49 $p1 = sprintf ("$cn/%02X", $d1);
50 &my_mkdir ($p1);
51 foreach $d2 (0..($NEW_SWAP_DIRECTORIES_L2-1)) {
52 $p2 = sprintf ("$p1/%02X", $d2);
53 &my_mkdir ($p2);
54 }
55 }
d36b569d 56}
57
58$newlog = "$swaplog.1.1";
59open (newlog, ">$newlog") || die "$newlog: $!\n";
60select(newlog); $|=1; select(STDOUT);
47f28373 61open (swaplog) || die "$swaplog: $!\n";
d36b569d 62$count = 0;
63while (<swaplog>) {
47f28373
FC
64 chop;
65 ($file,$url,$expires,$timestamp,$size) = split;
66 @F = split('/', $file);
67 $oldfileno = pop @F;
68 $oldpath = &old_fileno_to_path($oldfileno);
69 unless (@S = stat($oldpath)) {
70 print "$oldpath: $!\n";
71 next;
72 }
73 unless ($S[7] == $size) {
74 print "$oldpath: Wrong Size.\n";
75 next;
76 }
77 $newpath = &new_fileno_to_path($oldfileno);
78 next unless &my_link($oldpath,$newpath);
79 printf newlog "%08x %08x %08x %08x %9d %s\n",
80 $oldfileno,
81 $timestamp,
82 $expires,
83 $timestamp, # lastmod
84 $size,
85 $url;
86 $count++;
d36b569d 87}
88
89
90print <<EOF;
91Done converting.
92
93$count files were linked to the new directories.
94
95At this point you need to manually run these commands:
96EOF
97
98foreach $c (@cachedirs) {
99 print " /bin/mv $c $c.old; /bin/mv $c.new $c\n";
100}
101
102print <<EOF;
103 /bin/mv $swaplog $swaplog.old; /bin/mv $newlog $swaplog\n";
104
105And then start up Squid version 1.1.
106EOF
107exit(0);
108
109
110
111
112
113sub old_fileno_to_path {
47f28373
FC
114 local($fn) = @_;
115 sprintf ("%s/%02d/%d",
116 $cachedirs[$fn % $ncache_dirs],
117 ($fn / $ncache_dirs) % $OLD_SWAP_DIRECTORIES,
118 $fn);
d36b569d 119}
120
121sub new_fileno_to_path {
47f28373
FC
122 local($fn) = @_;
123 sprintf ("%s.new/%02X/%02X/%08X",
124 $cachedirs[$fn % $ncache_dirs],
125 ($fn / $ncache_dirs) % $NEW_SWAP_DIRECTORIES_L1,
126 ($fn / $ncache_dirs) / $NEW_SWAP_DIRECTORIES_L1 % $NEW_SWAP_DIRECTORIES_L2,
127 $fn);
d36b569d 128}
129
130sub my_mkdir {
47f28373
FC
131 local($p) = @_;
132 print "Making $p...\n";
133 return if ($dry_run);
134 unless (mkdir ($p, 0755)) {
135 return 1 if ($! == $EEXIST);
136 die "$p: $!\n";
137 }
d36b569d 138}
139
140sub my_link {
47f28373
FC
141 local($f,$t) = @_;
142 print "$f --> $t\n";
143 return 1 if ($dry_run);
144 unlink($t);
145 $rc = link ($f,$t);
146 warn "$t: $!\n" unless ($rc);
147 $rc;
d36b569d 148}