aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2003-09-29 17:13:36 +0000
committerJason Woodward2003-09-29 17:13:36 +0000
commit8d1657072acb76f57a277cebf64a8d92443e0106 (patch)
tree277a8521db9b48787eb1fde8b7983c19bc84ceb1
parent221345c99e6420dc18a9c50cae582c11a02a512c (diff)
downloadslapt-get-8d1657072acb76f57a277cebf64a8d92443e0106.tar.gz
unlink the bogus/empty/partial pkg file if d/l or checksum fails
-rw-r--r--ChangeLog1
-rw-r--r--src/curl.c25
2 files changed, 22 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index e359826..6df21b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
* error checking updates
* more verbose messages during operation
* fixed chdir/mkdir bug in working_dir
+ * unlink faulty d/l files/pkgs (failed to d/l or checksum is bad)
0.9.3 Sep 24, 2003
* default make target doesn't build slack pkg
diff --git a/src/curl.c b/src/curl.c
index db4d545..36eb5f5 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -160,7 +160,8 @@ char *download_pkg(const rc_config *global_config,pkg_info_t *pkg){
/* build the file name */
file_name = calloc(
- strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 , sizeof *file_name
+ strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 ,
+ sizeof *file_name
);
if( file_name == NULL ){
fprintf(stderr,"Failed to calloc file_name\n");
@@ -173,8 +174,7 @@ char *download_pkg(const rc_config *global_config,pkg_info_t *pkg){
file_name = strncat(file_name,".tgz",strlen(".tgz"));
/*
- * TODO: here we will use the md5sum (or some other means)
- * to see if the file is already present and valid
+ * here we will use the md5sum to see if the file is already present and valid
*/
if( ( fh_test = fopen(file_name,"r") ) != NULL){
/* check to see if the md5sum is correct */
@@ -190,7 +190,9 @@ char *download_pkg(const rc_config *global_config,pkg_info_t *pkg){
/* build the url */
url = calloc(
- strlen(global_config->mirror_url) + strlen(pkg->location) + strlen(file_name) + strlen("/") + 1 , sizeof *url
+ strlen(global_config->mirror_url) + strlen(pkg->location)
+ + strlen(file_name) + strlen("/") + 1,
+ sizeof *url
);
if( url == NULL ){
fprintf(stderr,"Failed to calloc url\n");
@@ -214,6 +216,14 @@ char *download_pkg(const rc_config *global_config,pkg_info_t *pkg){
printf("Done\n");
#endif
}else{
+ fclose(fh);
+ /* if the d/l fails, unlink the empty file */
+ if( unlink(file_name) == -1 ){
+ fprintf(stderr,"Failed to unlink %s\n",file_name);
+ if( errno ){
+ perror("unlink");
+ }
+ }
return NULL;
}
@@ -231,6 +241,13 @@ char *download_pkg(const rc_config *global_config,pkg_info_t *pkg){
fprintf(stderr,"MD5 expected: [%s]\n",md5_sum);
fprintf(stderr,"File: %s/%s\n",global_config->working_dir,file_name);
#endif
+ /* if the checksum fails, unlink the bogus file */
+ if( unlink(file_name) == -1 ){
+ fprintf(stderr,"Failed to unlink %s\n",file_name);
+ if( errno ){
+ perror("unlink");
+ }
+ }
return NULL;
}else{
printf("Done\n");