Subversion Repositories SvarDOS

Rev

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

Rev 227 Rev 230
Line 1... Line 1...
1
/*
1
/*
2
 * This file is part of FDNPKG
2
 * This file is part of pkginst (SvarDOS)
3
 * Copyright (C) 2012-2021 Mateusz Viste
3
 * Copyright (C) 2012-2021 Mateusz Viste
4
 * Changes by TK Chia
4
 * Changes by TK Chia
5
 */
5
 */
6
 
6
 
7
#include <ctype.h>     /* toupper() */
7
#include <ctype.h>     /* toupper() */
Line 135... Line 135...
135
  fclose(fd);
135
  fclose(fd);
136
}
136
}
137
 
137
 
138
 
138
 
139
/* returns 0 if pkgname is not installed, non-zero otherwise */
139
/* returns 0 if pkgname is not installed, non-zero otherwise */
140
int is_package_installed(char *pkgname, char *dosdir) {
140
int is_package_installed(const char *pkgname, const char *dosdir) {
141
  char fname[512];
141
  char fname[512];
142
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
142
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
143
  if (fileexists(fname) != 0) { /* file exists -> package is installed */
143
  return(fileexists(fname)); /* file exists -> package is installed */
144
    return(1);
-
 
145
  } else {
-
 
146
    return(0);
-
 
147
  }
-
 
148
}
144
}
149
 
145
 
150
 
146
 
151
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
147
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
152
int validate_package_not_installed(char *pkgname, char *dosdir) {
148
static int validate_package_not_installed(const char *pkgname, const char *dosdir) {
153
  if (is_package_installed(pkgname, dosdir) != 0) {
149
  if (is_package_installed(pkgname, dosdir) != 0) {
154
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
150
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
155
    puts("");
151
    puts("");
156
    return(-1);
152
    return(-1);
157
  }
153
  }
Line 168... Line 164...
168
  return(NULL);
164
  return(NULL);
169
}
165
}
170
 
166
 
171
 
167
 
172
/* prepare a package for installation. this is mandatory before actually installing it!
168
/* prepare a package for installation. this is mandatory before actually installing it!
173
 * returns a pointer to the zip file's index on success, NULL on failure. the *zipfile pointer is updated with a file descriptor to the open zip file to install. */
169
 * returns a pointer to the zip file's index on success, NULL on failure. the **zipfd pointer is updated with a file descriptor to the open zip file to install. */
174
struct ziplist *pkginstall_preparepackage(char *pkgname, char *localfile, int flags, FILE **zipfd, char *dosdir, struct customdirs *dirlist, char *buffmem1k) {
170
struct ziplist *pkginstall_preparepackage(char *pkgname, char *localfile, int flags, FILE **zipfd, char *dosdir, struct customdirs *dirlist, char *buffmem1k) {
175
  char *fname;
171
  char *fname;
176
  char *zipfile;
172
  char *zipfile;
177
  char *appinfofile;
173
  char *appinfofile;
178
  int appinfopresence;
174
  int appinfopresence;
179
  char *shortfile;
175
  char *shortfile;
180
  struct ziplist *ziplinkedlist, *curzipnode, *prevzipnode;
176
  struct ziplist *ziplinkedlist = NULL, *curzipnode, *prevzipnode;
181
  struct flist_t *flist;
177
  struct flist_t *flist = NULL;
182
 
178
 
183
  fname = buffmem1k;
179
  fname = buffmem1k;
184
  zipfile = buffmem1k + 256;
180
  zipfile = buffmem1k + 256;
185
  appinfofile = buffmem1k + 512;
181
  appinfofile = buffmem1k + 512;
186
 
182
 
Line 202... Line 198...
202
  /* Now let's check the content of the zip file */
198
  /* Now let's check the content of the zip file */
203
 
199
 
204
  *zipfd = fopen(zipfile, "rb");
200
  *zipfd = fopen(zipfile, "rb");
205
  if (*zipfd == NULL) {
201
  if (*zipfd == NULL) {
206
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
202
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
207
    return(NULL);
203
    goto RAII;
208
  }
204
  }
209
  ziplinkedlist = zip_listfiles(*zipfd);
205
  ziplinkedlist = zip_listfiles(*zipfd);
210
  if (ziplinkedlist == NULL) {
206
  if (ziplinkedlist == NULL) {
211
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
207
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
212
    fclose(*zipfd);
-
 
213
    return(NULL);
208
    goto RAII;
214
  }
209
  }
215
  /* if updating, load the list of files belonging to the current package */
210
  /* if updating, load the list of files belonging to the current package */
216
  if ((flags & PKGINST_UPDATE) != 0) {
211
  if ((flags & PKGINST_UPDATE) != 0) {
217
    flist = pkg_loadflist(pkgname, dosdir);
212
    flist = pkg_loadflist(pkgname, dosdir);
218
  } else {
-
 
219
    flist = NULL;
-
 
220
  }
213
  }
221
  /* Verify that there's no collision with existing local files, look for the appinfo presence, get rid of sources if required, and rename BAT links into COM files */
214
  /* Verify that there's no collision with existing local files, look for the appinfo presence, get rid of sources if required, and rename BAT links into COM files */
222
  appinfopresence = 0;
215
  appinfopresence = 0;
223
  prevzipnode = NULL;
216
  prevzipnode = NULL;
224
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
217
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
Line 255... Line 248...
255
    }
248
    }
256
    /* validate that the file has a valid filename (8+3, no shady chars...) */
249
    /* validate that the file has a valid filename (8+3, no shady chars...) */
257
    if (validfilename(curzipnode->filename) != 0) {
250
    if (validfilename(curzipnode->filename) != 0) {
258
      kitten_puts(3, 23, "Error: Package contains an invalid filename:");
251
      kitten_puts(3, 23, "Error: Package contains an invalid filename:");
259
      printf(" %s\n", curzipnode->filename);
252
      printf(" %s\n", curzipnode->filename);
260
      zip_freelist(&ziplinkedlist);
-
 
261
      fclose(*zipfd);
-
 
262
      return(NULL);
253
      goto RAII_ERR;
263
    }
254
    }
264
    /* look out for collisions with already existing files (unless we are
255
    /* look out for collisions with already existing files (unless we are
265
     * updating the package and the local file belongs to it */
256
     * updating the package and the local file belongs to it */
266
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
257
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
267
    strcat(fname, shortfile);
258
    strcat(fname, shortfile);
268
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
259
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
269
      kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
260
      kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
270
      printf(" %s\n", fname);
261
      printf(" %s\n", fname);
271
      zip_freelist(&ziplinkedlist);
-
 
272
      fclose(*zipfd);
-
 
273
      return(NULL);
262
      goto RAII_ERR;
274
    }
263
    }
275
    /* abort if any entry is encrypted */
264
    /* abort if any entry is encrypted */
276
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
265
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
277
      kitten_printf(3, 20, "Error: Package contains an encrypted file:");
266
      kitten_printf(3, 20, "Error: Package contains an encrypted file:");
278
      puts("");
267
      puts("");
279
      printf(" %s\n", curzipnode->filename);
268
      printf(" %s\n", curzipnode->filename);
280
      zip_freelist(&ziplinkedlist);
-
 
281
      fclose(*zipfd);
-
 
282
      return(NULL);
269
      goto RAII_ERR;
283
    }
270
    }
284
    /* abort if any file is compressed with an unsupported method */
271
    /* abort if any file is compressed with an unsupported method */
285
    if ((curzipnode->compmethod != 0/*store*/) && (curzipnode->compmethod != 8/*deflate*/)) { /* unsupported compression method */
272
    if ((curzipnode->compmethod != 0/*store*/) && (curzipnode->compmethod != 8/*deflate*/)) { /* unsupported compression method */
286
      kitten_printf(8, 2, "Error: Package contains a file compressed with an unsupported method (%d):", curzipnode->compmethod);
273
      kitten_printf(8, 2, "Error: Package contains a file compressed with an unsupported method (%d):", curzipnode->compmethod);
287
      puts("");
274
      puts("");
288
      printf(" %s\n", curzipnode->filename);
275
      printf(" %s\n", curzipnode->filename);
289
      zip_freelist(&ziplinkedlist);
-
 
290
      fclose(*zipfd);
-
 
291
      return(NULL);
276
      goto RAII_ERR;
292
    }
277
    }
293
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
278
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
294
    prevzipnode = curzipnode;
279
    prevzipnode = curzipnode;
295
    curzipnode = curzipnode->nextfile;
280
    curzipnode = curzipnode->nextfile;
296
  }
281
  }
297
  /* if appinfo file not found, this is not a real FreeDOS package */
282
  /* if appinfo file not found, this is not a real FreeDOS package */
298
  if (appinfopresence != 1) {
283
  if (appinfopresence != 1) {
299
    kitten_printf(3, 12, "Error: Package do not contain the %s file! Not a valid FreeDOS package.", appinfofile);
284
    kitten_printf(3, 12, "Error: Package do not contain the %s file! Not a valid FreeDOS package.", appinfofile);
300
    puts("");
285
    puts("");
-
 
286
    goto RAII_ERR;
-
 
287
  }
-
 
288
 
-
 
289
  goto RAII;
-
 
290
 
-
 
291
  RAII_ERR:
301
    zip_freelist(&ziplinkedlist);
292
  zip_freelist(&ziplinkedlist);
-
 
293
  ziplinkedlist = NULL;
-
 
294
  if ((zipfd != NULL) && (*zipfd != NULL)) {
302
    fclose(*zipfd);
295
    fclose(*zipfd);
303
    return(NULL);
296
    *zipfd = NULL;
304
  }
297
  }
305
 
298
 
-
 
299
  RAII:
-
 
300
  pkg_freeflist(flist);
306
  return(ziplinkedlist);
301
  return(ziplinkedlist);
307
}
302
}
308
 
303
 
309
 
304
 
310
/* install a package that has been prepared already. returns 0 on success,
305
/* install a package that has been prepared already. returns 0 on success,