diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-02-08 15:27:41 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-02-08 15:27:41 +0000 |
commit | c95ab9232965028df003af6f8a5a974c940cf35a (patch) | |
tree | 20abba2f69e96fd81b824acc6f37ca973d37b435 | |
parent | 903450d45350580131dc5acdf02b42d719d4650d (diff) |
Fixed infinite loop when attempting to download a file:/// directory on Unix (gp)
-rw-r--r-- | src/htsback.c | 6 | ||||
-rw-r--r-- | src/htslib.c | 12 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/htsback.c b/src/htsback.c index d026e7a..857e6be 100644 --- a/src/htsback.c +++ b/src/htsback.c @@ -2896,6 +2896,12 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache, "* * Fatal write error, giving up"); } back[i].r.is_write = 0; // erreur, abandonner + back[i].status = STATUS_READY; // terminé + back_set_finished(sback, i); + if (back[i].r.soc != INVALID_SOCKET) { + deletehttp(&back[i].r); + back[i].r.soc = INVALID_SOCKET; + } } else { #ifndef _WIN32 chmod(back[i].url_sav, HTS_ACCESS_FILE); diff --git a/src/htslib.c b/src/htslib.c index b52756a..450a4b8 100644 --- a/src/htslib.c +++ b/src/htslib.c @@ -700,8 +700,6 @@ T_SOC http_xfopen(httrackp * opt, int mode, int treat, int waitconnect, soc = INVALID_SOCKET; if (retour->totalsize < 0) strcpybuff(retour->msg, "Unable to open local file"); - else if (retour->totalsize == 0) - strcpybuff(retour->msg, "File empty"); else { // Note: On passe par un FILE* (plus propre) //soc=open(fil,O_RDONLY,0); // en lecture seule! @@ -4351,7 +4349,7 @@ off_t fsize(const char *s) { if (!strnotempty(s)) // nom vide: erreur return -1; - if (stat(s, &st) == 0) { + if (stat(s, &st) == 0 && S_ISREG(st.st_mode)) { return st.st_size; } else { return -1; @@ -4365,7 +4363,7 @@ off_t fsize_utf8(const char *s) { if (!strnotempty(s)) // nom vide: erreur return -1; - if (STAT(s, &st) == 0) { + if (STAT(s, &st) == 0 && S_ISREG(st.st_mode)) { return st.st_size; } else { return -1; @@ -4500,9 +4498,11 @@ int hts_read(htsblk * r, char *buff, int size) { #if HTS_WIDE_DEBUG DEBUG_W("read(%p, %d, %d)\n" _(void *)buff _(int) size _(int) r->fp); #endif - if (r->fp) + if (r->fp) { retour = (int) fread(buff, 1, size, r->fp); - else + if (retour == 0) // can happen with directories (!) + retour = READ_ERROR; + } else retour = READ_ERROR; } else { #if HTS_WIDE_DEBUG |