Ensure found files are actually files
We located files in a few places but didn't check if they were files or directories. Ensure they are actually files using stat() and S_ISREG(); this showed itself when trying to download to the directory name itself in FS#22645. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
f892775366
commit
7467fb9e76
2 changed files with 4 additions and 3 deletions
|
@ -128,13 +128,13 @@ static int download_internal(const char *url, const char *localpath,
|
||||||
destfile = get_destfile(localpath, filename);
|
destfile = get_destfile(localpath, filename);
|
||||||
tempfile = get_tempfile(localpath, filename);
|
tempfile = get_tempfile(localpath, filename);
|
||||||
|
|
||||||
if(stat(tempfile, &st) == 0 && st.st_size > 0) {
|
if(stat(tempfile, &st) == 0 && S_ISREG(st.st_mode) && st.st_size > 0) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "tempfile found, attempting continuation\n");
|
_alpm_log(PM_LOG_DEBUG, "tempfile found, attempting continuation\n");
|
||||||
local_time = fileurl->last_modified = st.st_mtime;
|
local_time = fileurl->last_modified = st.st_mtime;
|
||||||
local_size = fileurl->offset = (off_t)st.st_size;
|
local_size = fileurl->offset = (off_t)st.st_size;
|
||||||
dl_thisfile = st.st_size;
|
dl_thisfile = st.st_size;
|
||||||
localf = fopen(tempfile, "ab");
|
localf = fopen(tempfile, "ab");
|
||||||
} else if(!force && stat(destfile, &st) == 0 && st.st_size > 0) {
|
} else if(!force && stat(destfile, &st) == 0 && S_ISREG(st.st_mode) && st.st_size > 0) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "destfile found, using mtime only\n");
|
_alpm_log(PM_LOG_DEBUG, "destfile found, using mtime only\n");
|
||||||
local_time = fileurl->last_modified = st.st_mtime;
|
local_time = fileurl->last_modified = st.st_mtime;
|
||||||
local_size = /* no fu->off here */ (off_t)st.st_size;
|
local_size = /* no fu->off here */ (off_t)st.st_size;
|
||||||
|
|
|
@ -608,12 +608,13 @@ char *_alpm_filecache_find(const char* filename)
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char *retpath;
|
char *retpath;
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
struct stat buf;
|
||||||
|
|
||||||
/* Loop through the cache dirs until we find a matching file */
|
/* Loop through the cache dirs until we find a matching file */
|
||||||
for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
|
for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
|
||||||
snprintf(path, PATH_MAX, "%s%s", (char*)alpm_list_getdata(i),
|
snprintf(path, PATH_MAX, "%s%s", (char*)alpm_list_getdata(i),
|
||||||
filename);
|
filename);
|
||||||
if(access(path, R_OK) == 0) {
|
if(stat(path, &buf) == 0 && S_ISREG(buf.st_mode)) {
|
||||||
retpath = strdup(path);
|
retpath = strdup(path);
|
||||||
_alpm_log(PM_LOG_DEBUG, "found cached pkg: %s\n", retpath);
|
_alpm_log(PM_LOG_DEBUG, "found cached pkg: %s\n", retpath);
|
||||||
return(retpath);
|
return(retpath);
|
||||||
|
|
Loading…
Add table
Reference in a new issue