From 00c70e3b1f7d6cc715c7dde64a56471e7bc8e5db Mon Sep 17 00:00:00 2001 From: HuangHaitao Date: Mon, 10 Mar 2025 09:46:35 +0800 Subject: [PATCH] XTS for HTTPDataOption failed. Signed-off-by: HuangHaitao --- lib/mime.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/mime.c b/lib/mime.c index 6c716e774..1f94afee2 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -1436,35 +1436,36 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) char *base; struct_stat sbuf; - if(stat(filename, &sbuf)) + if(stat(filename, &sbuf) || access(filename, R_OK)) result = CURLE_READ_ERROR; + + part->data = strdup(filename); + if (!part->data) + result = CURLE_OUT_OF_MEMORY; + + part->datasize = -1; + if (!result && S_ISREG(sbuf.st_mode)) { + part->datasize = filesize(filename, sbuf); + part->seekfunc = mime_file_seek; + } + + part->readfunc = mime_file_read; + part->freefunc = mime_file_free; + part->kind = MIMEKIND_FILE; + + /* As a side effect, set the filename to the current file's base name. + It is possible to withdraw this by explicitly calling + curl_mime_filename() with a NULL filename argument after the current + call. */ + base = strippath(filename); + if (!base) + result = CURLE_OUT_OF_MEMORY; else { - part->data = strdup(filename); - if(!part->data) - result = CURLE_OUT_OF_MEMORY; - else { - part->datasize = -1; - if(S_ISREG(sbuf.st_mode)) { - part->datasize = filesize(filename, sbuf); - part->seekfunc = mime_file_seek; - } + CURLcode res = curl_mime_filename(part, base); - part->readfunc = mime_file_read; - part->freefunc = mime_file_free; - part->kind = MIMEKIND_FILE; - - /* As a side effect, set the filename to the current file's base name. - It is possible to withdraw this by explicitly calling - curl_mime_filename() with a NULL filename argument after the current - call. */ - base = strippath(filename); - if(!base) - result = CURLE_OUT_OF_MEMORY; - else { - result = curl_mime_filename(part, base); - free(base); - } - } + if (res) + result = res; + free(base); } } return result; -- Gitee