Subversion Repositories SvarDOS

Rev

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

Rev 269 Rev 272
Line 113... Line 113...
113
 
113
 
114
  /* Now let's check the content of the zip file */
114
  /* Now let's check the content of the zip file */
115
 
115
 
116
  *zipfd = fopen(zipfile, "rb");
116
  *zipfd = fopen(zipfile, "rb");
117
  if (*zipfd == NULL) {
117
  if (*zipfd == NULL) {
118
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
118
    kitten_puts(3, 8, "ERROR: Invalid zip archive! Package not installed.");
119
    goto RAII;
119
    goto RAII;
120
  }
120
  }
121
  ziplinkedlist = zip_listfiles(*zipfd);
121
  ziplinkedlist = zip_listfiles(*zipfd);
122
  if (ziplinkedlist == NULL) {
122
  if (ziplinkedlist == NULL) {
123
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
123
    kitten_puts(3, 8, "ERROR: Invalid zip archive! Package not installed.");
124
    goto RAII;
124
    goto RAII;
125
  }
125
  }
126
  /* if updating, load the list of files belonging to the current package */
126
  /* if updating, load the list of files belonging to the current package */
127
  if ((flags & PKGINST_UPDATE) != 0) {
127
  if ((flags & PKGINST_UPDATE) != 0) {
128
    flist = pkg_loadflist(pkgname, dosdir);
128
    flist = pkg_loadflist(pkgname, dosdir);
Line 155... Line 155...
155
      }
155
      }
156
      continue; /* go to the next item */
156
      continue; /* go to the next item */
157
    }
157
    }
158
    /* validate that the file has a valid filename (8+3, no shady chars...) */
158
    /* validate that the file has a valid filename (8+3, no shady chars...) */
159
    if (validfilename(curzipnode->filename) != 0) {
159
    if (validfilename(curzipnode->filename) != 0) {
160
      kitten_puts(3, 23, "Error: Package contains an invalid filename:");
160
      kitten_puts(3, 23, "ERROR: Package contains an invalid filename:");
161
      printf(" %s\n", curzipnode->filename);
161
      printf(" %s\n", curzipnode->filename);
162
      goto RAII_ERR;
162
      goto RAII_ERR;
163
    }
163
    }
164
    /* look out for collisions with already existing files (unless we are
164
    /* look out for collisions with already existing files (unless we are
165
     * updating the package and the local file belongs to it */
165
     * updating the package and the local file belongs to it */
166
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
166
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
167
    strcat(fname, shortfile);
167
    strcat(fname, shortfile);
168
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
168
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
169
      kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
169
      kitten_puts(3, 9, "ERROR: Package contains a file that already exists locally:");
170
      printf(" %s\n", fname);
170
      printf(" %s\n", fname);
171
      goto RAII_ERR;
171
      goto RAII_ERR;
172
    }
172
    }
173
    /* abort if any entry is encrypted */
173
    /* abort if any entry is encrypted */
174
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
174
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
175
      kitten_printf(3, 20, "Error: Package contains an encrypted file:");
175
      kitten_printf(3, 20, "ERROR: Package contains an encrypted file:");
176
      puts("");
176
      puts("");
177
      printf(" %s\n", curzipnode->filename);
177
      printf(" %s\n", curzipnode->filename);
178
      goto RAII_ERR;
178
      goto RAII_ERR;
179
    }
179
    }
180
    /* abort if any file is compressed with an unsupported method */
180
    /* abort if any file is compressed with an unsupported method */
181
    if ((curzipnode->compmethod != 0/*store*/) && (curzipnode->compmethod != 8/*deflate*/)) { /* unsupported compression method */
181
    if ((curzipnode->compmethod != 0/*store*/) && (curzipnode->compmethod != 8/*deflate*/)) { /* unsupported compression method */
182
      kitten_printf(8, 2, "Error: Package contains a file compressed with an unsupported method (%d):", curzipnode->compmethod);
182
      kitten_printf(8, 2, "ERROR: Package contains a file compressed with an unsupported method (%d):", curzipnode->compmethod);
183
      puts("");
183
      puts("");
184
      printf(" %s\n", curzipnode->filename);
184
      printf(" %s\n", curzipnode->filename);
185
      goto RAII_ERR;
185
      goto RAII_ERR;
186
    }
186
    }
187
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
187
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
188
    prevzipnode = curzipnode;
188
    prevzipnode = curzipnode;
189
    curzipnode = curzipnode->nextfile;
189
    curzipnode = curzipnode->nextfile;
190
  }
190
  }
191
  /* if appinfo file not found, this is not a real FreeDOS package */
191
  /* if appinfo file not found, this is not a real FreeDOS package */
192
  if (appinfopresence != 1) {
192
  if (appinfopresence != 1) {
193
    kitten_printf(3, 12, "Error: Package do not contain the %s file! Not a valid FreeDOS package.", appinfofile);
193
    kitten_printf(3, 12, "ERROR: Package do not contain the %s file! Not a valid FreeDOS package.", appinfofile);
194
    puts("");
194
    puts("");
195
    goto RAII_ERR;
195
    goto RAII_ERR;
196
  }
196
  }
197
 
197
 
198
  goto RAII;
198
  goto RAII;
Line 225... Line 225...
225
  sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
225
  sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
226
 
226
 
227
  buff = malloc(512);
227
  buff = malloc(512);
228
  fulldestfilename = malloc(1024);
228
  fulldestfilename = malloc(1024);
229
  if ((buff == NULL) || (fulldestfilename == NULL)) {
229
  if ((buff == NULL) || (fulldestfilename == NULL)) {
230
    kitten_puts(8, 0, "Out of memory!");
230
    kitten_printf(2, 14, "Out of memory! (%s)", "fulldestfilename");
-
 
231
    puts("");
231
    zip_freelist(&ziplinkedlist);
232
    zip_freelist(&ziplinkedlist);
232
    free(buff);
233
    free(buff);
233
    free(fulldestfilename);
234
    free(fulldestfilename);
234
    return(-1);
235
    return(-1);
235
  }
236
  }
Line 240... Line 241...
240
 
241
 
241
  /* open the lst file */
242
  /* open the lst file */
242
  sprintf(buff, "%s\\%s", dosdir, packageslst);
243
  sprintf(buff, "%s\\%s", dosdir, packageslst);
243
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
244
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
244
  if (lstfd == NULL) {
245
  if (lstfd == NULL) {
245
    kitten_printf(3, 10, "Error: Could not create %s!", buff);
246
    kitten_printf(3, 10, "ERROR: Could not create %s!", buff);
246
    puts("");
247
    puts("");
247
    zip_freelist(&ziplinkedlist);
248
    zip_freelist(&ziplinkedlist);
248
    free(buff);
249
    free(buff);
249
    free(fulldestfilename);
250
    free(fulldestfilename);
250
    return(-2);
251
    return(-2);
Line 262... Line 263...
262
    mkpath(buff);
263
    mkpath(buff);
263
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
264
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
264
    /* Now unzip the file */
265
    /* Now unzip the file */
265
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
266
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
266
    if (unzip_result != 0) {
267
    if (unzip_result != 0) {
267
      kitten_printf(8, 3, "Error while extracting '%s' to '%s'!", curzipnode->filename, fulldestfilename);
268
      kitten_printf(8, 3, "ERROR: failed extracting '%s' to '%s'!", curzipnode->filename, fulldestfilename);
268
      printf(" [%d]\n", unzip_result);
269
      printf(" [%d]\n", unzip_result);
269
      filesextractedfailure += 1;
270
      filesextractedfailure += 1;
270
    } else {
271
    } else {
271
      printf(" %s -> %s\n", curzipnode->filename, buff);
272
      printf(" %s -> %s\n", curzipnode->filename, buff);
272
      filesextractedsuccess += 1;
273
      filesextractedsuccess += 1;