Subversion Repositories SvarDOS

Rev

Rev 730 | Rev 734 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 730 Rev 731
Line 74... Line 74...
74
  $zip->close();
74
  $zip->close();
75
  return($res);
75
  return($res);
76
}
76
}
77
 
77
 
78
 
78
 
-
 
79
function read_list_of_files_in_zip($z) {
-
 
80
  $zip = new ZipArchive;
-
 
81
  if ($zip->open($z, ZipArchive::RDONLY) !== true) {
-
 
82
    echo "ERROR: failed to open zip file '{$z}'\n";
-
 
83
    return(false);
-
 
84
  }
-
 
85
 
-
 
86
  $res = array();
-
 
87
  for ($i = 0; $i < $zip->numFiles; $i++) $res[] = $zip->getNameIndex($i);
-
 
88
 
-
 
89
  $zip->close();
-
 
90
  return($res);
-
 
91
}
-
 
92
 
-
 
93
 
79
// reads a LSM string and returns it in the form of an array
94
// reads a LSM string and returns it in the form of an array
80
function parse_lsm($s) {
95
function parse_lsm($s) {
81
  $res = array();
96
  $res = array();
82
  for ($l = strtok($s, "\n"); $l !== false; $l = strtok("\n")) {
97
  for ($l = strtok($s, "\n"); $l !== false; $l = strtok("\n")) {
83
    // the line is "token: value", let's find the colon
98
    // the line is "token: value", let's find the colon
Line 89... Line 104...
89
  }
104
  }
90
  return($res);
105
  return($res);
91
}
106
}
92
 
107
 
93
 
108
 
-
 
109
// on PHP 8+ there is str_starts_with(), but not on PHP 7 so I use this
-
 
110
function str_head_is($haystack, $needle) {
-
 
111
  return strpos($haystack, $needle) === 0;
-
 
112
}
-
 
113
 
-
 
114
 
94
// ***************** MAIN ROUTINE *********************************************
115
// ***************** MAIN ROUTINE *********************************************
95
 
116
 
96
//echo "SvarDOS repository index generator ver {$PVER}\n";
117
//echo "SvarDOS repository index generator ver {$PVER}\n";
97
 
118
 
98
if (($_SERVER['argc'] != 2) || ($_SERVER['argv'][1][0] == '-')) {
119
if (($_SERVER['argc'] != 2) || ($_SERVER['argv'][1][0] == '-')) {
Line 132... Line 153...
132
  if (empty($lsmarray['description'])) {
153
  if (empty($lsmarray['description'])) {
133
    echo "ERROR: lsm file in {$fname} does not contain a description\n";
154
    echo "ERROR: lsm file in {$fname} does not contain a description\n";
134
    continue;
155
    continue;
135
  }
156
  }
136
 
157
 
-
 
158
  // validate the files present in the archive
-
 
159
  $listoffiles = read_list_of_files_in_zip($pkgfullpath);
-
 
160
  foreach ($listoffiles as $f) {
-
 
161
    $f = strtolower($f);
-
 
162
    // LSM file is ok
-
 
163
    if ($f === "appinfo/{$pkgnam}.lsm") continue;
-
 
164
    if ($f === "appinfo/") continue;
-
 
165
    // well-known dirs are okay
-
 
166
    if (str_head_is($f, 'bin/')) continue;
-
 
167
    if (str_head_is($f, "doc/{$pkgnam}/")) continue;
-
 
168
    if ($f === 'doc/') continue;
-
 
169
    if (str_head_is($f, "nls/{$pkgnam}.")) continue;
-
 
170
    if ($f === 'nls/') continue;
-
 
171
    if (str_head_is($f, "progs/{$pkgnam}/")) continue;
-
 
172
    if ($f === 'progs/') continue;
-
 
173
    if (str_head_is($f, "devel/{$pkgnam}/")) continue;
-
 
174
    if ($f === 'devel/') continue;
-
 
175
    if (str_head_is($f, "games/{$pkgnam}/")) continue;
-
 
176
    if ($f === 'games/') continue;
-
 
177
    if (str_head_is($f, "drivers/{$pkgnam}/")) continue;
-
 
178
    if ($f === 'drivers/') continue;
-
 
179
    echo "WARNING: pkg {$fname} contains a file in an illegal location: {$f}\n";
-
 
180
  }
-
 
181
 
137
  $meta['fname'] = $fname;
182
  $meta['fname'] = $fname;
138
  $meta['desc'] = $lsmarray['description'];
183
  $meta['desc'] = $lsmarray['description'];
139
 
184
 
140
  $pkgdb[$pkgnam][$lsmarray['version']] = $meta;
185
  $pkgdb[$pkgnam][$lsmarray['version']] = $meta;
141
}
186
}