Subversion Repositories SvarDOS

Rev

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

Rev 224 Rev 225
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, char *mapdrv) {
140
int is_package_installed(char *pkgname, 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
  mapdrives(fname, mapdrv);
-
 
144
  if (fileexists(fname) != 0) { /* file exists -> package is installed */
143
  if (fileexists(fname) != 0) { /* file exists -> package is installed */
145
    return(1);
144
    return(1);
146
  } else {
145
  } else {
147
    return(0);
146
    return(0);
148
  }
147
  }
149
}
148
}
150
 
149
 
151
 
150
 
152
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
151
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
153
int validate_package_not_installed(char *pkgname, char *dosdir, char *mapdrv) {
152
int validate_package_not_installed(char *pkgname, char *dosdir) {
154
  if (is_package_installed(pkgname, dosdir, mapdrv) != 0) {
153
  if (is_package_installed(pkgname, dosdir) != 0) {
155
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
154
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
156
    puts("");
155
    puts("");
157
    return(-1);
156
    return(-1);
158
  }
157
  }
159
  return(0);
158
  return(0);
Line 170... Line 169...
170
}
169
}
171
 
170
 
172
 
171
 
173
/* prepare a package for installation. this is mandatory before actually installing it!
172
/* prepare a package for installation. this is mandatory before actually installing it!
174
 * 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. */
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. */
175
struct ziplist *pkginstall_preparepackage(struct pkgdb *pkgdb, char *pkgname, char *tempdir, char *localfile, int flags, char **repolist, FILE **zipfd, char *proxy, int proxyport, char *downloadingstring, char *dosdir, struct customdirs *dirlist, char *buffmem1k, char *mapdrv) {
174
struct ziplist *pkginstall_preparepackage(char *pkgname, char *localfile, int flags, FILE **zipfd, char *dosdir, struct customdirs *dirlist, char *buffmem1k) {
176
  char *fname;
175
  char *fname;
177
  char *zipfile;
176
  char *zipfile;
178
  char *appinfofile;
177
  char *appinfofile;
179
  int appinfopresence;
178
  int appinfopresence;
180
  char *shortfile;
179
  char *shortfile;
Line 188... Line 187...
188
  strtolower(pkgname); /* convert pkgname to lower case, because the http repo is probably case sensitive */
187
  strtolower(pkgname); /* convert pkgname to lower case, because the http repo is probably case sensitive */
189
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
188
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
190
 
189
 
191
  /* check if not already installed, if already here, print a message "you might want to use update instead"
190
  /* check if not already installed, if already here, print a message "you might want to use update instead"
192
   * of course this must not be done if we are in the process of upgrading said package */
191
   * of course this must not be done if we are in the process of upgrading said package */
193
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir, mapdrv) != 0)) {
192
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir) != 0)) {
194
    return(NULL);
193
    return(NULL);
195
  }
194
  }
196
 
195
 
197
  if (localfile != NULL) {  /* if it's a local file, then we will have to skip all the network stuff */
196
  if (localfile != NULL) {  /* if it's a local file, then we will have to skip all the network stuff */
198
    strcpy(zipfile, localfile);
197
    strcpy(zipfile, localfile);
Line 269... Line 268...
269
      return(NULL);
268
      return(NULL);
270
    }
269
    }
271
    /* look out for collisions with already existing files (unless we are
270
    /* look out for collisions with already existing files (unless we are
272
     * updating the package and the local file belongs to it */
271
     * updating the package and the local file belongs to it */
273
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
272
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
274
    mapdrives(fname, mapdrv);
-
 
275
    strcat(fname, shortfile);
273
    strcat(fname, shortfile);
276
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
274
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
277
      kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
275
      kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
278
      printf(" %s\n", fname);
276
      printf(" %s\n", fname);
279
      zip_freelist(&ziplinkedlist);
277
      zip_freelist(&ziplinkedlist);
Line 315... Line 313...
315
}
313
}
316
 
314
 
317
 
315
 
318
/* install a package that has been prepared already. returns 0 on success,
316
/* install a package that has been prepared already. returns 0 on success,
319
 * or a negative value on error, or a positive value on warning */
317
 * or a negative value on error, or a positive value on warning */
320
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd, char *mapdrv) {
318
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
321
  char *buff;
319
  char *buff;
322
  char *fulldestfilename;
320
  char *fulldestfilename;
323
  char packageslst[64];
321
  char packageslst[64];
324
  char *shortfile;
322
  char *shortfile;
325
  long filesextractedsuccess = 0, filesextractedfailure = 0;
323
  long filesextractedsuccess = 0, filesextractedfailure = 0;
Line 342... Line 340...
342
  sprintf(buff, "%s\\packages\\", dosdir);
340
  sprintf(buff, "%s\\packages\\", dosdir);
343
  mkpath(buff);
341
  mkpath(buff);
344
 
342
 
345
  /* open the lst file */
343
  /* open the lst file */
346
  sprintf(buff, "%s\\%s", dosdir, packageslst);
344
  sprintf(buff, "%s\\%s", dosdir, packageslst);
347
  mapdrives(buff, mapdrv);
-
 
348
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
345
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
349
  if (lstfd == NULL) {
346
  if (lstfd == NULL) {
350
    kitten_printf(3, 10, "Error: Could not create %s!", buff);
347
    kitten_printf(3, 10, "Error: Could not create %s!", buff);
351
    puts("");
348
    puts("");
352
    zip_freelist(&ziplinkedlist);
349
    zip_freelist(&ziplinkedlist);
Line 361... Line 358...
361
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
358
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
362
    if (strcasecmp(curzipnode->filename, packageslst) == 0) continue; /* skip silently the package.lst file, if found */
359
    if (strcasecmp(curzipnode->filename, packageslst) == 0) continue; /* skip silently the package.lst file, if found */
363
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
360
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
364
    /* log the filename to packages\pkg.lst (with original, unmapped drive) */
361
    /* log the filename to packages\pkg.lst (with original, unmapped drive) */
365
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
362
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
366
    /* remap drive letter, if needed (AFTER writing to lstfd) */
-
 
367
    mapdrives(buff, mapdrv);
-
 
368
    /* create the path, just in case it doesn't exist yet */
363
    /* create the path, just in case it doesn't exist yet */
369
    mkpath(buff);
364
    mkpath(buff);
370
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
365
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
371
    /* Now unzip the file */
366
    /* Now unzip the file */
372
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
367
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
Line 378... Line 373...
378
      printf(" %s -> %s\n", curzipnode->filename, buff);
373
      printf(" %s -> %s\n", curzipnode->filename, buff);
379
      filesextractedsuccess += 1;
374
      filesextractedsuccess += 1;
380
    }
375
    }
381
    /* if it's a LINK file, recompute a new content */
376
    /* if it's a LINK file, recompute a new content */
382
    if (islinkfile(curzipnode->filename) != 0) {
377
    if (islinkfile(curzipnode->filename) != 0) {
383
      unmapdrives(buff, mapdrv);
-
 
384
      processlinkfile(fulldestfilename, dosdir, dirlist, buff);
378
      processlinkfile(fulldestfilename, dosdir, dirlist, buff);
385
    }
379
    }
386
  }
380
  }
387
  fclose(lstfd);
381
  fclose(lstfd);
388
 
382