Subversion Repositories SvarDOS

Rev

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

Rev 1957 Rev 1963
Line 75... Line 75...
75
 
75
 
76
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
76
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
77
static int validate_package_not_installed(const char *pkgname, const char *dosdir) {
77
static int validate_package_not_installed(const char *pkgname, const char *dosdir) {
78
  if (is_package_installed(pkgname, dosdir) != 0) {
78
  if (is_package_installed(pkgname, dosdir) != 0) {
79
    kitten_printf(3, 18, pkgname); /* "Package %s is already installed! You might want to use the 'update' action." */
79
    kitten_printf(3, 18, pkgname); /* "Package %s is already installed! You might want to use the 'update' action." */
80
    puts("");
80
    outputnl("");
81
    return(-1);
81
    return(-1);
82
  }
82
  }
83
  return(0);
83
  return(0);
84
}
84
}
85
 
85
 
Line 117... Line 117...
117
    if ((slen < 4) || (fname[slen - 4] != '.')) strcat(fname, ".SVP");
117
    if ((slen < 4) || (fname[slen - 4] != '.')) strcat(fname, ".SVP");
118
  }
118
  }
119
 
119
 
120
  /* does the file exist? */
120
  /* does the file exist? */
121
  if (!fileexists(fname)) {
121
  if (!fileexists(fname)) {
122
    puts(svarlang_str(10, 1)); /* ERROR: File not found */
122
    outputnl(svarlang_str(10, 1)); /* ERROR: File not found */
123
    goto RAII;
123
    goto RAII;
124
  }
124
  }
125
 
125
 
126
  /* open the SVP archive and get the list of files */
126
  /* open the SVP archive and get the list of files */
127
  *zipfd = fopen(fname, "rb");
127
  *zipfd = fopen(fname, "rb");
128
  if (*zipfd == NULL) {
128
  if (*zipfd == NULL) {
129
    puts(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
129
    outputnl(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
130
    goto RAII_ERR;
130
    goto RAII_ERR;
131
  }
131
  }
132
  ziplinkedlist = zip_listfiles(*zipfd);
132
  ziplinkedlist = zip_listfiles(*zipfd);
133
  if (ziplinkedlist == NULL) {
133
  if (ziplinkedlist == NULL) {
134
    puts(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
134
    outputnl(svarlang_str(3, 8)); /* "ERROR: Invalid zip archive! Package not installed." */
135
    goto RAII_ERR;
135
    goto RAII_ERR;
136
  }
136
  }
137
 
137
 
138
  /* process the entire ziplist and sanitize it + locate the appinfo file so
138
  /* process the entire ziplist and sanitize it + locate the appinfo file so
139
   * I know the package name */
139
   * I know the package name */
Line 145... Line 145...
145
    slash2backslash(curzipnode->filename);
145
    slash2backslash(curzipnode->filename);
146
    strlwr(curzipnode->filename);
146
    strlwr(curzipnode->filename);
147
 
147
 
148
    /* validate that the file has a valid filename (8+3, no shady chars...) */
148
    /* validate that the file has a valid filename (8+3, no shady chars...) */
149
    if (validfilename(curzipnode->filename) != 0) {
149
    if (validfilename(curzipnode->filename) != 0) {
150
      puts(svarlang_str(3, 23)); /* "ERROR: Package contains an invalid filename:" */
150
      outputnl(svarlang_str(3, 23)); /* "ERROR: Package contains an invalid filename:" */
151
      printf(" %s\n", curzipnode->filename);
151
      printf(" %s\n", curzipnode->filename);
152
      goto RAII_ERR;
152
      goto RAII_ERR;
153
    }
153
    }
154
 
154
 
155
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
155
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
156
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) goto DELETE_ZIP_NODE;
156
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) goto DELETE_ZIP_NODE;
157
 
157
 
158
    /* abort if entry is encrypted */
158
    /* abort if entry is encrypted */
159
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
159
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
160
      puts(svarlang_str(3, 20)); /* "ERROR: Package contains an encrypted file:" */
160
      outputnl(svarlang_str(3, 20)); /* "ERROR: Package contains an encrypted file:" */
161
      printf(" %s\n", curzipnode->filename);
161
      printf(" %s\n", curzipnode->filename);
162
      goto RAII_ERR;
162
      goto RAII_ERR;
163
    }
163
    }
164
 
164
 
165
    /* abort if file is compressed with an unsupported method */
165
    /* abort if file is compressed with an unsupported method */
166
    if ((curzipnode->compmethod != ZIP_METH_STORE) && (curzipnode->compmethod != ZIP_METH_DEFLATE)) { /* unsupported compression method */
166
    if ((curzipnode->compmethod != ZIP_METH_STORE) && (curzipnode->compmethod != ZIP_METH_DEFLATE)) { /* unsupported compression method */
167
      kitten_printf(8, 2, curzipnode->compmethod); /* "ERROR: Package contains a file compressed with an unsupported method (%d):" */
167
      kitten_printf(8, 2, curzipnode->compmethod); /* "ERROR: Package contains a file compressed with an unsupported method (%d):" */
168
      puts("");
168
      outputnl("");
169
      printf(" %s\n", curzipnode->filename);
169
      printf(" %s\n", curzipnode->filename);
170
      goto RAII_ERR;
170
      goto RAII_ERR;
171
    }
171
    }
172
 
172
 
173
    /* is it the appinfo file? detach it from the list for now */
173
    /* is it the appinfo file? detach it from the list for now */
174
    if (strstr(curzipnode->filename, "appinfo\\") == curzipnode->filename) {
174
    if (strstr(curzipnode->filename, "appinfo\\") == curzipnode->filename) {
175
      if (appinfoptr != NULL) {
175
      if (appinfoptr != NULL) {
176
        puts(svarlang_str(3, 12)); /* "ERROR: This is not a valid SvarDOS package" */
176
        outputnl(svarlang_str(3, 12)); /* "ERROR: This is not a valid SvarDOS package" */
177
        goto RAII_ERR;
177
        goto RAII_ERR;
178
      }
178
      }
179
      appinfoptr = curzipnode;
179
      appinfoptr = curzipnode;
180
      curzipnode = curzipnode->nextfile;
180
      curzipnode = curzipnode->nextfile;
181
      if (prevzipnode == NULL) {
181
      if (prevzipnode == NULL) {
Line 204... Line 204...
204
    /* go to the next item */
204
    /* go to the next item */
205
  }
205
  }
206
 
206
 
207
  /* if appinfo file not found, this is not a SvarDOS package */
207
  /* if appinfo file not found, this is not a SvarDOS package */
208
  if (appinfoptr == NULL) {
208
  if (appinfoptr == NULL) {
209
    puts(svarlang_str(3, 12)); /* "ERROR: This is not a valid SvarDOS package." */
209
    outputnl(svarlang_str(3, 12)); /* "ERROR: This is not a valid SvarDOS package." */
210
    goto RAII_ERR;
210
    goto RAII_ERR;
211
  }
211
  }
212
 
212
 
213
  /* attach the appinfo node to the top of the list (installation second stage
213
  /* attach the appinfo node to the top of the list (installation second stage
214
   * relies on this) */
214
   * relies on this) */
Line 223... Line 223...
223
      if (appinfoptr->filename[8 + i] == '.') break;
223
      if (appinfoptr->filename[8 + i] == '.') break;
224
      pkgname[i] = appinfoptr->filename[8 + i];
224
      pkgname[i] = appinfoptr->filename[8 + i];
225
    }
225
    }
226
    pkgname[i] = 0;
226
    pkgname[i] = 0;
227
    if ((i == 0) || (strcmp(appinfoptr->filename + 8 + i, ".lsm") != 0)) {
227
    if ((i == 0) || (strcmp(appinfoptr->filename + 8 + i, ".lsm") != 0)) {
228
      puts(svarlang_str(3, 12)); /* "ERROR: This is not a valid SvarDOS package." */
228
      outputnl(svarlang_str(3, 12)); /* "ERROR: This is not a valid SvarDOS package." */
229
      goto RAII_ERR;
229
      goto RAII_ERR;
230
    }
230
    }
231
  }
231
  }
232
 
232
 
233
  /* if updating, load the list of files belonging to the current package */
233
  /* if updating, load the list of files belonging to the current package */
Line 246... Line 246...
246
    /* look out for collisions with already existing files (unless we are
246
    /* look out for collisions with already existing files (unless we are
247
     * updating the package and the local file belongs to it */
247
     * updating the package and the local file belongs to it */
248
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist, bootdrive);
248
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist, bootdrive);
249
    strcat(fname, shortfile);
249
    strcat(fname, shortfile);
250
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
250
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
251
      puts(svarlang_str(3, 9)); /* "ERROR: Package contains a file that already exists locally:" */
251
      outputnl(svarlang_str(3, 9)); /* "ERROR: Package contains a file that already exists locally:" */
252
      printf(" %s\n", fname);
252
      printf(" %s\n", fname);
253
      goto RAII_ERR;
253
      goto RAII_ERR;
254
    }
254
    }
255
  }
255
  }
256
 
256
 
Line 283... Line 283...
283
  while (freadtokval(fd, buff, buffsz, &msgptr, ':') == 0) {
283
  while (freadtokval(fd, buff, buffsz, &msgptr, ':') == 0) {
284
    if (msgptr != NULL) {
284
    if (msgptr != NULL) {
285
      if (strcasecmp(buff, "warn") == 0) {
285
      if (strcasecmp(buff, "warn") == 0) {
286
        /* print a visual delimiter */
286
        /* print a visual delimiter */
287
        if (warncount == 0) {
287
        if (warncount == 0) {
288
          puts("");
288
          outputnl("");
289
          for (i = 0; i < 79; i++) putchar('*');
289
          for (i = 0; i < 79; i++) putchar('*');
290
          puts("");
290
          outputnl("");
291
        }
291
        }
292
        /* there may be more than one "warn" line */
292
        /* there may be more than one "warn" line */
293
        puts(msgptr);
293
        outputnl(msgptr);
294
        warncount++;
294
        warncount++;
295
      }
295
      }
296
    }
296
    }
297
  }
297
  }
298
 
298
 
299
  fclose(fd);
299
  fclose(fd);
300
 
300
 
301
  /* if one or more warn lines have been displayed then close with a delimiter again */
301
  /* if one or more warn lines have been displayed then close with a delimiter again */
302
  if (warncount > 0) {
302
  if (warncount > 0) {
303
    for (i = 0; i < 79; i++) putchar('*');
303
    for (i = 0; i < 79; i++) putchar('*');
304
    puts("");
304
    outputnl("");
305
  }
305
  }
306
 
306
 
307
}
307
}
308
 
308
 
309
 
309
 
Line 328... Line 328...
328
  output(" -> ");
328
  output(" -> ");
329
  output(buff);
329
  output(buff);
330
  strcat(buff, pkgname);
330
  strcat(buff, pkgname);
331
  strcat(buff, ".lsm");
331
  strcat(buff, ".lsm");
332
  unzip_result = zip_unzip(zipfd, ziplinkedlist, buff);
332
  unzip_result = zip_unzip(zipfd, ziplinkedlist, buff);
333
  puts("");
333
  outputnl("");
334
  if (unzip_result != 0) {
334
  if (unzip_result != 0) {
335
    kitten_printf(10, 4, unzip_result); /* "ERROR: unzip failure (%d)" */
335
    kitten_printf(10, 4, unzip_result); /* "ERROR: unzip failure (%d)" */
336
    puts("");
336
    outputnl("");
337
    return(-1);
337
    return(-1);
338
  }
338
  }
339
  filesextractedsuccess++;
339
  filesextractedsuccess++;
340
 
340
 
341
  /* open the (freshly created) LSM file */
341
  /* open the (freshly created) LSM file */
342
  lsmfd = fopen(buff, "ab"); /* opening in APPEND mode so I do not loose the LSM content */
342
  lsmfd = fopen(buff, "ab"); /* opening in APPEND mode so I do not loose the LSM content */
343
  if (lsmfd == NULL) {
343
  if (lsmfd == NULL) {
344
    kitten_printf(3, 10, buff); /* "ERROR: Could not create %s!" */
344
    kitten_printf(3, 10, buff); /* "ERROR: Could not create %s!" */
345
    puts("");
345
    outputnl("");
346
    return(-2);
346
    return(-2);
347
  }
347
  }
348
  fprintf(lsmfd, "\r\n"); /* in case the LSM does not end with a clear line already */
348
  fprintf(lsmfd, "\r\n"); /* in case the LSM does not end with a clear line already */
349
 
349
 
350
  /* write list of files in zip into the lst, and create the directories structure */
350
  /* write list of files in zip into the lst, and create the directories structure */
Line 363... Line 363...
363
    /* Now unzip the file */
363
    /* Now unzip the file */
364
    output(curzipnode->filename);
364
    output(curzipnode->filename);
365
    output(" -> ");
365
    output(" -> ");
366
    output(buff);
366
    output(buff);
367
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
367
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
368
    puts("");
368
    outputnl("");
369
    if (unzip_result != 0) {
369
    if (unzip_result != 0) {
370
      kitten_printf(10, 4, unzip_result); /* "ERROR: unzip failure (%d)" */
370
      kitten_printf(10, 4, unzip_result); /* "ERROR: unzip failure (%d)" */
371
      puts("");
371
      outputnl("");
372
      filesextractedfailure += 1;
372
      filesextractedfailure += 1;
373
    } else {
373
    } else {
374
      filesextractedsuccess += 1;
374
      filesextractedsuccess += 1;
375
    }
375
    }
376
  }
376
  }
377
  fclose(lsmfd);
377
  fclose(lsmfd);
378
 
378
 
379
  kitten_printf(3, 19, pkgname, filesextractedfailure, filesextractedsuccess); /* "Package %s installed: %ld errors, %ld files extracted." */
379
  kitten_printf(3, 19, pkgname, filesextractedfailure, filesextractedsuccess); /* "Package %s installed: %ld errors, %ld files extracted." */
380
  puts("");
380
  outputnl("");
381
 
381
 
382
  /* scan the LSM file for a "warn" message to display */
382
  /* scan the LSM file for a "warn" message to display */
383
  display_warn_if_exists(pkgname, dosdir, buff, sizeof(buff));
383
  display_warn_if_exists(pkgname, dosdir, buff, sizeof(buff));
384
 
384
 
385
  return(filesextractedfailure);
385
  return(filesextractedfailure);