Annotation of wpscripts/ezreturn/index.pm, Revision 1.1.1.1
1.1 yason 1: package index;
2:
3: use strict;
4:
5: # where to search for .index files
6: our @BVOLUMES = ("/B1", "/B2", "/usr/backup", ""); # terminate search with ""
7:
8: # wideprint related index files
9: our $WPZ_INDEX = "wp_zayavki.index";
10: our $WPP_INDEX = "wp_proba.index";
11:
12: # epd related index files
13: our $EPDZ_INDEX= "epd_zayavki.index";
14: our $EPDP_INDEX= "epd_proba.index";
15:
16: # wideprint related directories
17: our $WPZ_DIR = "wp/zayavki";
18: our $WPP_DIR = "wp/proba";
19:
20: # epd related directories
21: our $EPDZ_DIR= "epd/zayavki";
22: our $EPDP_DIR= "epd/proba";
23:
24:
25: sub lookup($$)
26: {
27: my $file_type = shift;
28: my $file_name = shift;
29: my $bvolume;
30: my @indexfile;
31: my $bfilename;
32: my $bfilepath;
33:
34: # lookup file in backups using .index files
35:
36: foreach $bvolume (@BVOLUMES) {
37: # stop if "" encountered
38: if ($bvolume eq "") {
39: print "[index::lookup] $file_name not found on @BVOLUMES\n";
40:
41: return("");
42: }
43:
44: if ($file_type eq "wpz") {
45: # see if we can read index file
46: if (! -r "$bvolume/$WPZ_INDEX") {
47: die("index::lookup() can't open $bvolume/$WPZ_INDEX");
48: }
49:
50: $bfilename = `grep ^$file_name $bvolume/$WPZ_INDEX`;
51: chomp($bfilename);
52:
53: if ($bfilename ne "" ) {
54: # file_name has been found in index on this bvolume
55:
56: $bfilepath = "$bvolume/$WPZ_DIR/$bfilename";
57:
58: # check for file existence
59: if (-e $bfilepath) {
60: # file exists
61: print "[index::lookup] found $bfilepath\n";
62:
63: return($bfilepath);
64: # NOTREACHED
65: } # else, file listed in index but we can't stat it
66: print "[index::lookup] $bfilename listed in $bvolume/$WPZ_INDEX but it doesn't exist\n";
67: # will look in next bvolume
68: # next
69:
70: } # else, file hasn't been found in index on that bvolume
71: # proceed to next bvolume, if any
72: next;
73: } # ! "wpz"
74:
75: if ($file_type eq "wpp") {
76: # see if we can read index file
77: if (! -r "$bvolume/$WPP_INDEX") {
78: die("index::lookup() can't open $bvolume/$WPP_INDEX");
79: }
80:
81: $bfilename = `grep ^$file_name $bvolume/$WPP_INDEX`;
82: chomp($bfilename);
83:
84: if ($bfilename ne "" ) {
85: # file_name has been found in index on this bvolume
86:
87: $bfilepath = "$bvolume/$WPP_DIR/$bfilename";
88:
89: # check for file existence
90: if (-e $bfilepath) {
91: # file exists
92: print "[index::lookup] found $bfilepath\n";
93:
94: return($bfilepath);
95: # NOTREACHED
96: } # else, file listed in index but we can't stat it
97: print "[index::lookup] $bfilename listed in $bvolume/$WPP_INDEX but it doesn't exist\n";
98: # will look in next bvolume
99: # next
100:
101: } # else, file hasn't been found in index on that bvolume
102: # proceed to next bvolume, if any
103: next;
104: } # ! "wpp"
105:
106: if ($file_type eq "epdz") {
107: # see if we can read index file
108: if (! -r "$bvolume/$EPDZ_INDEX") {
109: die("index::lookup() can't open $bvolume/$EPDZ_INDEX");
110: }
111:
112: $bfilename = `grep ^$file_name $bvolume/$EPDZ_INDEX`;
113: chomp($bfilename);
114:
115: if ($bfilename ne "" ) {
116: # file_name has been found in index on this bvolume
117:
118: $bfilepath = "$bvolume/$EPDZ_DIR/$bfilename";
119:
120: # check for file existence
121: if (-e $bfilepath) {
122: # file exists
123: print "[index::lookup] found $bfilepath\n";
124:
125: return($bfilepath);
126: # NOTREACHED
127: } # else, file listed in index but we can't stat it
128: print "[index::lookup] $bfilename listed in $bvolume/$EPDZ_INDEX but it doesn't exist\n";
129: # will look in next bvolume
130: # next
131:
132: } # else, file hasn't been found in index on that bvolume
133: # proceed to next bvolume, if any
134: next;
135: } # ! "epdz"
136:
137: if ($file_type eq "epdp") {
138: # see if we can read index file
139: if (! -r "$bvolume/$EPDP_INDEX") {
140: die("index::lookup() can't open $bvolume/$EPDP_INDEX");
141: }
142:
143: $bfilename = `grep ^$file_name $bvolume/$EPDP_INDEX`;
144: chomp($bfilename);
145:
146: if ($bfilename ne "" ) {
147: # file_name has been found in index on this bvolume
148:
149: $bfilepath = "$bvolume/$EPDP_DIR/$bfilename";
150:
151: # check for file existence
152: if (-e $bfilepath) {
153: # file exists
154: print "[index::lookup] found $bfilepath\n";
155:
156: return($bfilepath);
157: # NOTREACHED
158: } # else, file listed in index but we can't stat it
159: print "[index::lookup] $bfilename listed in $bvolume/$EPDP_INDEX but it doesn't exist\n";
160: # will look in next bvolume
161: # next
162:
163: } # else, file hasn't been found in index on that bvolume
164: # proceed to next bvolume, if any
165: next;
166: } # ! "epdp"
167:
168: }
169:
170: }
171:
172: return 1;
173:
CVSweb