Subversion Repositories SvarDOS

Rev

Rev 260 | Rev 268 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 260 Rev 263
1
/*
1
/*
2
 * This file is part of pkginst (SvarDOS)
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
-
 
5
 */
4
 */
6
 
5
 
7
#include <ctype.h>     /* toupper() */
6
#include <ctype.h>     /* toupper() */
8
#include <stdio.h>
7
#include <stdio.h>
9
#include <stdlib.h>    /* system() */
8
#include <stdlib.h>    /* system() */
10
#include <string.h>    /* strcpy() */
9
#include <string.h>    /* strcpy() */
11
#include <unistd.h>    /* read() */
10
#include <unistd.h>    /* read() */
12
#include <sys/types.h> /* struct utimbuf */
11
#include <sys/types.h> /* struct utimbuf */
13
 
12
 
14
#include "crc32.h"     /* all CRC32 related stuff */
-
 
15
#include "helpers.h"   /* slash2backslash(), strtolower() */
13
#include "helpers.h"   /* slash2backslash(), strtolower() */
16
#include "fileexst.h"
14
#include "fileexst.h"
17
#include "kprintf.h"
15
#include "kprintf.h"
18
#include "libunzip.h"  /* zip_listfiles()... */
16
#include "libunzip.h"  /* zip_listfiles()... */
19
#include "showinst.h"  /* pkg_loadflist() */
17
#include "showinst.h"  /* pkg_loadflist() */
20
#include "pkginst.h"   /* include self for control */
18
#include "pkginst.h"   /* include self for control */
21
#include "version.h"
19
#include "version.h"
22
 
20
 
23
 
21
 
24
/* validate a filename (8+3, no weird characters, etc). returns 0 on success,
22
/* validate a filename (8+3, no weird characters, etc). returns 0 on success,
25
 * nonzero otherwise. */
23
 * nonzero otherwise. */
26
static int validfilename(const char *fname) {
24
static int validfilename(const char *fname) {
27
  int i, i2;
25
  int i, i2;
28
  char *validchars = "!#$%&'()-@^_`{}~";
26
  char *validchars = "!#$%&'()-@^_`{}~";
29
  int elemlen = 0;
27
  int elemlen = 0;
30
  int elemmaxlen = 8; /* switches from 8 to 3 depending wheter I am analyzing
28
  int elemmaxlen = 8; /* switches from 8 to 3 depending wheter I am analyzing
31
                         a filename or an extension */
29
                         a filename or an extension */
32
  /* look for invalid chars in the entire string, and check the length of the
30
  /* look for invalid chars in the entire string, and check the length of the
33
   * element at the same time */
31
   * element at the same time */
34
  for (i = 0; fname[i] != 0; i++) {
32
  for (i = 0; fname[i] != 0; i++) {
35
    /* director separators are threated specially */
33
    /* director separators are threated specially */
36
    if (fname[i] == '\\') {
34
    if (fname[i] == '\\') {
37
      elemlen = 0;
35
      elemlen = 0;
38
      elemmaxlen = 8;
36
      elemmaxlen = 8;
39
      continue;
37
      continue;
40
    }
38
    }
41
    /* '.' switches the check into extension mode */
39
    /* '.' switches the check into extension mode */
42
    if (fname[i] == '.') {
40
    if (fname[i] == '.') {
43
      if (elemlen == 0) return(-1); /* a file must have a base name */
41
      if (elemlen == 0) return(-1); /* a file must have a base name */
44
      if (elemmaxlen == 3) return(-2); /* a file cannot have two extensions */
42
      if (elemmaxlen == 3) return(-2); /* a file cannot have two extensions */
45
      elemlen = 0;
43
      elemlen = 0;
46
      elemmaxlen = 3;
44
      elemmaxlen = 3;
47
      continue;
45
      continue;
48
    }
46
    }
49
    /* check that the element is not too long */
47
    /* check that the element is not too long */
50
    if (++elemlen > elemmaxlen) return(-3);
48
    if (++elemlen > elemmaxlen) return(-3);
51
    /* look for valid characters */
49
    /* look for valid characters */
52
    if ((fname[i] >= 'a') && (fname[i] <= 'z')) continue;
50
    if ((fname[i] >= 'a') && (fname[i] <= 'z')) continue;
53
    if ((fname[i] >= 'A') && (fname[i] <= 'Z')) continue;
51
    if ((fname[i] >= 'A') && (fname[i] <= 'Z')) continue;
54
    if ((fname[i] >= '0') && (fname[i] <= '9')) continue;
52
    if ((fname[i] >= '0') && (fname[i] <= '9')) continue;
55
    if ((fname[i] & 128) != 0) continue; /* high bytes are okay (NLS) */
53
    if ((fname[i] & 128) != 0) continue; /* high bytes are okay (NLS) */
56
    /* look for other valid characters */
54
    /* look for other valid characters */
57
    for (i2 = 0; validchars[i2] != 0; i2++) {
55
    for (i2 = 0; validchars[i2] != 0; i2++) {
58
      if (fname[i] == validchars[i2]) break;
56
      if (fname[i] == validchars[i2]) break;
59
    }
57
    }
60
    if (validchars[i2] != 0) continue;
58
    if (validchars[i2] != 0) continue;
61
    /* if we are here, then the character is invalid */
59
    /* if we are here, then the character is invalid */
62
    return(-4);
60
    return(-4);
63
  }
61
  }
64
  /* all checks passed */
62
  /* all checks passed */
65
  return(0);
63
  return(0);
66
}
64
}
67
 
65
 
68
 
66
 
69
/* returns 0 if pkgname is not installed, non-zero otherwise */
67
/* returns 0 if pkgname is not installed, non-zero otherwise */
70
int is_package_installed(const char *pkgname, const char *dosdir) {
68
int is_package_installed(const char *pkgname, const char *dosdir) {
71
  char fname[512];
69
  char fname[512];
72
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
70
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
73
  return(fileexists(fname)); /* file exists -> package is installed */
71
  return(fileexists(fname)); /* file exists -> package is installed */
74
}
72
}
75
 
73
 
76
 
74
 
77
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
75
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
78
static int validate_package_not_installed(const char *pkgname, const char *dosdir) {
76
static int validate_package_not_installed(const char *pkgname, const char *dosdir) {
79
  if (is_package_installed(pkgname, dosdir) != 0) {
77
  if (is_package_installed(pkgname, dosdir) != 0) {
80
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
78
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
81
    puts("");
79
    puts("");
82
    return(-1);
80
    return(-1);
83
  }
81
  }
84
  return(0);
82
  return(0);
85
}
83
}
86
 
84
 
87
 
85
 
88
/* find a filename in a flist linked list, and returns a pointer to it */
86
/* find a filename in a flist linked list, and returns a pointer to it */
89
static struct flist_t *findfileinlist(struct flist_t *flist, const char *fname) {
87
static struct flist_t *findfileinlist(struct flist_t *flist, const char *fname) {
90
  while (flist != NULL) {
88
  while (flist != NULL) {
91
    if (strcasecmp(flist->fname, fname) == 0) return(flist);
89
    if (strcasecmp(flist->fname, fname) == 0) return(flist);
92
    flist = flist->next;
90
    flist = flist->next;
93
  }
91
  }
94
  return(NULL);
92
  return(NULL);
95
}
93
}
96
 
94
 
97
 
95
 
98
/* prepare a package for installation. this is mandatory before actually installing it!
96
/* prepare a package for installation. this is mandatory before actually installing it!
99
 * 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. */
97
 * 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. */
100
struct ziplist *pkginstall_preparepackage(const char *pkgname, const char *zipfile, int flags, FILE **zipfd, const char *dosdir, const struct customdirs *dirlist) {
98
struct ziplist *pkginstall_preparepackage(const char *pkgname, const char *zipfile, int flags, FILE **zipfd, const char *dosdir, const struct customdirs *dirlist) {
101
  char fname[256];
99
  char fname[256];
102
  char appinfofile[256];
100
  char appinfofile[256];
103
  int appinfopresence;
101
  int appinfopresence;
104
  char *shortfile;
102
  char *shortfile;
105
  struct ziplist *ziplinkedlist = NULL, *curzipnode, *prevzipnode;
103
  struct ziplist *ziplinkedlist = NULL, *curzipnode, *prevzipnode;
106
  struct flist_t *flist = NULL;
104
  struct flist_t *flist = NULL;
107
 
105
 
108
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
106
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
109
 
107
 
110
  /* check if not already installed, if already here, print a message "you might want to use update instead"
108
  /* check if not already installed, if already here, print a message "you might want to use update instead"
111
   * of course this must not be done if we are in the process of upgrading said package */
109
   * of course this must not be done if we are in the process of upgrading said package */
112
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir) != 0)) {
110
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir) != 0)) {
113
    return(NULL);
111
    return(NULL);
114
  }
112
  }
115
 
113
 
116
  /* Now let's check the content of the zip file */
114
  /* Now let's check the content of the zip file */
117
 
115
 
118
  *zipfd = fopen(zipfile, "rb");
116
  *zipfd = fopen(zipfile, "rb");
119
  if (*zipfd == NULL) {
117
  if (*zipfd == NULL) {
120
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
118
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
121
    goto RAII;
119
    goto RAII;
122
  }
120
  }
123
  ziplinkedlist = zip_listfiles(*zipfd);
121
  ziplinkedlist = zip_listfiles(*zipfd);
124
  if (ziplinkedlist == NULL) {
122
  if (ziplinkedlist == NULL) {
125
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
123
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
126
    goto RAII;
124
    goto RAII;
127
  }
125
  }
128
  /* 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 */
129
  if ((flags & PKGINST_UPDATE) != 0) {
127
  if ((flags & PKGINST_UPDATE) != 0) {
130
    flist = pkg_loadflist(pkgname, dosdir);
128
    flist = pkg_loadflist(pkgname, dosdir);
131
  }
129
  }
132
  /* Verify that there's no collision with existing local files, look for the appinfo presence */
130
  /* Verify that there's no collision with existing local files, look for the appinfo presence */
133
  appinfopresence = 0;
131
  appinfopresence = 0;
134
  prevzipnode = NULL;
132
  prevzipnode = NULL;
135
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
133
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
136
    /* change all slashes to backslashes, and switch into all-lowercase */
134
    /* change all slashes to backslashes, and switch into all-lowercase */
137
    slash2backslash(curzipnode->filename);
135
    slash2backslash(curzipnode->filename);
138
    strtolower(curzipnode->filename);
136
    strtolower(curzipnode->filename);
139
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
137
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
140
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) {
138
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) {
141
      curzipnode->filename[0] = 0; /* mark it "empty", will be removed in a short moment */
139
      curzipnode->filename[0] = 0; /* mark it "empty", will be removed in a short moment */
142
    }
140
    }
143
    /* is it a "link file"? skip it - link files are no longer supported */
141
    /* is it a "link file"? skip it - link files are no longer supported */
144
    if (fdnpkg_strcasestr(curzipnode->filename, "links\\") == curzipnode->filename) {
142
    if (fdnpkg_strcasestr(curzipnode->filename, "links\\") == curzipnode->filename) {
145
      curzipnode->filename[0] = 0; /* in fact, I just mark the file as 'empty' on the filename - see later below */
143
      curzipnode->filename[0] = 0; /* in fact, I just mark the file as 'empty' on the filename - see later below */
146
    }
144
    }
147
 
145
 
148
    if (curzipnode->filename[0] == 0) { /* ignore empty filenames (maybe it was empty originally, or has been emptied because it's a dropped source or link) */
146
    if (curzipnode->filename[0] == 0) { /* ignore empty filenames (maybe it was empty originally, or has been emptied because it's a dropped source or link) */
149
      if (prevzipnode == NULL) {  /* take the item out of the list */
147
      if (prevzipnode == NULL) {  /* take the item out of the list */
150
        ziplinkedlist = curzipnode->nextfile;
148
        ziplinkedlist = curzipnode->nextfile;
151
        free(curzipnode); /* free the item */
149
        free(curzipnode); /* free the item */
152
        curzipnode = ziplinkedlist;
150
        curzipnode = ziplinkedlist;
153
      } else {
151
      } else {
154
        prevzipnode->nextfile = curzipnode->nextfile;
152
        prevzipnode->nextfile = curzipnode->nextfile;
155
        free(curzipnode); /* free the item */
153
        free(curzipnode); /* free the item */
156
        curzipnode = prevzipnode->nextfile;
154
        curzipnode = prevzipnode->nextfile;
157
      }
155
      }
158
      continue; /* go to the next item */
156
      continue; /* go to the next item */
159
    }
157
    }
160
    /* 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...) */
161
    if (validfilename(curzipnode->filename) != 0) {
159
    if (validfilename(curzipnode->filename) != 0) {
162
      kitten_puts(3, 23, "Error: Package contains an invalid filename:");
160
      kitten_puts(3, 23, "Error: Package contains an invalid filename:");
163
      printf(" %s\n", curzipnode->filename);
161
      printf(" %s\n", curzipnode->filename);
164
      goto RAII_ERR;
162
      goto RAII_ERR;
165
    }
163
    }
166
    /* look out for collisions with already existing files (unless we are
164
    /* look out for collisions with already existing files (unless we are
167
     * updating the package and the local file belongs to it */
165
     * updating the package and the local file belongs to it */
168
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
166
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
169
    strcat(fname, shortfile);
167
    strcat(fname, shortfile);
170
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
168
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
171
      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:");
172
      printf(" %s\n", fname);
170
      printf(" %s\n", fname);
173
      goto RAII_ERR;
171
      goto RAII_ERR;
174
    }
172
    }
175
    /* abort if any entry is encrypted */
173
    /* abort if any entry is encrypted */
176
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
174
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
177
      kitten_printf(3, 20, "Error: Package contains an encrypted file:");
175
      kitten_printf(3, 20, "Error: Package contains an encrypted file:");
178
      puts("");
176
      puts("");
179
      printf(" %s\n", curzipnode->filename);
177
      printf(" %s\n", curzipnode->filename);
180
      goto RAII_ERR;
178
      goto RAII_ERR;
181
    }
179
    }
182
    /* abort if any file is compressed with an unsupported method */
180
    /* abort if any file is compressed with an unsupported method */
183
    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 */
184
      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);
185
      puts("");
183
      puts("");
186
      printf(" %s\n", curzipnode->filename);
184
      printf(" %s\n", curzipnode->filename);
187
      goto RAII_ERR;
185
      goto RAII_ERR;
188
    }
186
    }
189
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
187
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
190
    prevzipnode = curzipnode;
188
    prevzipnode = curzipnode;
191
    curzipnode = curzipnode->nextfile;
189
    curzipnode = curzipnode->nextfile;
192
  }
190
  }
193
  /* 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 */
194
  if (appinfopresence != 1) {
192
  if (appinfopresence != 1) {
195
    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);
196
    puts("");
194
    puts("");
197
    goto RAII_ERR;
195
    goto RAII_ERR;
198
  }
196
  }
199
 
197
 
200
  goto RAII;
198
  goto RAII;
201
 
199
 
202
  RAII_ERR:
200
  RAII_ERR:
203
  zip_freelist(&ziplinkedlist);
201
  zip_freelist(&ziplinkedlist);
204
  ziplinkedlist = NULL;
202
  ziplinkedlist = NULL;
205
  if ((zipfd != NULL) && (*zipfd != NULL)) {
203
  if ((zipfd != NULL) && (*zipfd != NULL)) {
206
    fclose(*zipfd);
204
    fclose(*zipfd);
207
    *zipfd = NULL;
205
    *zipfd = NULL;
208
  }
206
  }
209
 
207
 
210
  RAII:
208
  RAII:
211
  pkg_freeflist(flist);
209
  pkg_freeflist(flist);
212
  return(ziplinkedlist);
210
  return(ziplinkedlist);
213
}
211
}
214
 
212
 
215
 
213
 
216
/* install a package that has been prepared already. returns 0 on success,
214
/* install a package that has been prepared already. returns 0 on success,
217
 * or a negative value on error, or a positive value on warning */
215
 * or a negative value on error, or a positive value on warning */
218
int pkginstall_installpackage(const char *pkgname, const char *dosdir, const struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
216
int pkginstall_installpackage(const char *pkgname, const char *dosdir, const struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd) {
219
  char *buff;
217
  char *buff;
220
  char *fulldestfilename;
218
  char *fulldestfilename;
221
  char packageslst[64];
219
  char packageslst[64];
222
  char *shortfile;
220
  char *shortfile;
223
  long filesextractedsuccess = 0, filesextractedfailure = 0;
221
  long filesextractedsuccess = 0, filesextractedfailure = 0;
224
  struct ziplist *curzipnode;
222
  struct ziplist *curzipnode;
225
  FILE *lstfd;
223
  FILE *lstfd;
226
 
224
 
227
  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 */
228
 
226
 
229
  buff = malloc(512);
227
  buff = malloc(512);
230
  fulldestfilename = malloc(1024);
228
  fulldestfilename = malloc(1024);
231
  if ((buff == NULL) || (fulldestfilename == NULL)) {
229
  if ((buff == NULL) || (fulldestfilename == NULL)) {
232
    kitten_puts(8, 0, "Out of memory!");
230
    kitten_puts(8, 0, "Out of memory!");
233
    zip_freelist(&ziplinkedlist);
231
    zip_freelist(&ziplinkedlist);
234
    free(buff);
232
    free(buff);
235
    free(fulldestfilename);
233
    free(fulldestfilename);
236
    return(-1);
234
    return(-1);
237
  }
235
  }
238
 
236
 
239
  /* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
237
  /* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
240
  sprintf(buff, "%s\\packages\\", dosdir);
238
  sprintf(buff, "%s\\packages\\", dosdir);
241
  mkpath(buff);
239
  mkpath(buff);
242
 
240
 
243
  /* open the lst file */
241
  /* open the lst file */
244
  sprintf(buff, "%s\\%s", dosdir, packageslst);
242
  sprintf(buff, "%s\\%s", dosdir, packageslst);
245
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
243
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
246
  if (lstfd == NULL) {
244
  if (lstfd == NULL) {
247
    kitten_printf(3, 10, "Error: Could not create %s!", buff);
245
    kitten_printf(3, 10, "Error: Could not create %s!", buff);
248
    puts("");
246
    puts("");
249
    zip_freelist(&ziplinkedlist);
247
    zip_freelist(&ziplinkedlist);
250
    free(buff);
248
    free(buff);
251
    free(fulldestfilename);
249
    free(fulldestfilename);
252
    return(-2);
250
    return(-2);
253
  }
251
  }
254
 
252
 
255
  /* write list of files in zip into the lst, and create the directories structure */
253
  /* write list of files in zip into the lst, and create the directories structure */
256
  for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
254
  for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
257
    int unzip_result;
255
    int unzip_result;
258
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
256
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
259
    if (strcasecmp(curzipnode->filename, packageslst) == 0) continue; /* skip silently the package.lst file, if found */
257
    if (strcasecmp(curzipnode->filename, packageslst) == 0) continue; /* skip silently the package.lst file, if found */
260
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
258
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
261
    /* log the filename to packages\pkg.lst (with original, unmapped drive) */
259
    /* log the filename to packages\pkg.lst (with original, unmapped drive) */
262
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
260
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
263
    /* create the path, just in case it doesn't exist yet */
261
    /* create the path, just in case it doesn't exist yet */
264
    mkpath(buff);
262
    mkpath(buff);
265
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
263
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
266
    /* Now unzip the file */
264
    /* Now unzip the file */
267
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
265
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
268
    if (unzip_result != 0) {
266
    if (unzip_result != 0) {
269
      kitten_printf(8, 3, "Error while extracting '%s' to '%s'!", curzipnode->filename, fulldestfilename);
267
      kitten_printf(8, 3, "Error while extracting '%s' to '%s'!", curzipnode->filename, fulldestfilename);
270
      printf(" [%d]\n", unzip_result);
268
      printf(" [%d]\n", unzip_result);
271
      filesextractedfailure += 1;
269
      filesextractedfailure += 1;
272
    } else {
270
    } else {
273
      printf(" %s -> %s\n", curzipnode->filename, buff);
271
      printf(" %s -> %s\n", curzipnode->filename, buff);
274
      filesextractedsuccess += 1;
272
      filesextractedsuccess += 1;
275
    }
273
    }
276
  }
274
  }
277
  fclose(lstfd);
275
  fclose(lstfd);
278
 
276
 
279
  /* free the ziplist and close file descriptor */
277
  /* free the ziplist and close file descriptor */
280
  zip_freelist(&ziplinkedlist);
278
  zip_freelist(&ziplinkedlist);
281
  free(buff);
279
  free(buff);
282
  free(fulldestfilename);
280
  free(fulldestfilename);
283
 
281
 
284
  kitten_printf(3, 19, "Package %s installed: %ld files extracted, %ld errors.", pkgname, filesextractedsuccess, filesextractedfailure);
282
  kitten_printf(3, 19, "Package %s installed: %ld files extracted, %ld errors.", pkgname, filesextractedsuccess, filesextractedfailure);
285
  puts("");
283
  puts("");
286
  return(filesextractedfailure);
284
  return(filesextractedfailure);
287
}
285
}
288
 
286