mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-01-03 13:07:24 +00:00
use correct content-type when overwriting and copying files
This commit is contained in:
parent
0536dc1112
commit
ae4bcd405c
21
src/curl.cpp
21
src/curl.cpp
@ -2961,13 +2961,14 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
|
|||||||
responseHeaders.clear();
|
responseHeaders.clear();
|
||||||
bodydata.Clear();
|
bodydata.Clear();
|
||||||
|
|
||||||
|
string contype = S3fsCurl::LookupMimeType(string(tpath));
|
||||||
|
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
|
||||||
|
|
||||||
// Make request headers
|
// Make request headers
|
||||||
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
||||||
string key = lower(iter->first);
|
string key = lower(iter->first);
|
||||||
string value = iter->second;
|
string value = iter->second;
|
||||||
if(key == "content-type"){
|
if(key.substr(0, 9) == "x-amz-acl"){
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
|
||||||
}else if(key.substr(0, 9) == "x-amz-acl"){
|
|
||||||
// not set value, but after set it.
|
// not set value, but after set it.
|
||||||
}else if(key.substr(0, 10) == "x-amz-meta"){
|
}else if(key.substr(0, 10) == "x-amz-meta"){
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
||||||
@ -3106,12 +3107,13 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
|||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", strMD5.c_str());
|
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", strMD5.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string contype = S3fsCurl::LookupMimeType(string(tpath));
|
||||||
|
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
|
||||||
|
|
||||||
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
||||||
string key = lower(iter->first);
|
string key = lower(iter->first);
|
||||||
string value = iter->second;
|
string value = iter->second;
|
||||||
if(key == "content-type"){
|
if(key.substr(0, 9) == "x-amz-acl"){
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
|
||||||
}else if(key.substr(0, 9) == "x-amz-acl"){
|
|
||||||
// not set value, but after set it.
|
// not set value, but after set it.
|
||||||
}else if(key.substr(0, 10) == "x-amz-meta"){
|
}else if(key.substr(0, 10) == "x-amz-meta"){
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
||||||
@ -3714,13 +3716,14 @@ int S3fsCurl::CopyMultipartPostSetup(const char* from, const char* to, int part_
|
|||||||
bodydata.Clear();
|
bodydata.Clear();
|
||||||
headdata.Clear();
|
headdata.Clear();
|
||||||
|
|
||||||
|
string contype = S3fsCurl::LookupMimeType(string(to));
|
||||||
|
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
|
||||||
|
|
||||||
// Make request headers
|
// Make request headers
|
||||||
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
||||||
string key = lower(iter->first);
|
string key = lower(iter->first);
|
||||||
string value = iter->second;
|
string value = iter->second;
|
||||||
if(key == "content-type"){
|
if(key == "x-amz-copy-source"){
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
|
||||||
}else if(key == "x-amz-copy-source"){
|
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
||||||
}else if(key == "x-amz-copy-source-range"){
|
}else if(key == "x-amz-copy-source-range"){
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
|
||||||
|
@ -75,6 +75,12 @@ function test_mv_file {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#check the renamed file content-type
|
||||||
|
if [ -f "/etc/mime.types" ]
|
||||||
|
then
|
||||||
|
check_content_type "$1/$ALT_TEST_TEXT_FILE" "text/plain"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check the contents of the alt file
|
# Check the contents of the alt file
|
||||||
ALT_FILE_LENGTH=`wc -c $ALT_TEST_TEXT_FILE | awk '{print $1}'`
|
ALT_FILE_LENGTH=`wc -c $ALT_TEST_TEXT_FILE | awk '{print $1}'`
|
||||||
if [ "$ALT_FILE_LENGTH" -ne "$ALT_TEXT_LENGTH" ]
|
if [ "$ALT_FILE_LENGTH" -ne "$ALT_TEXT_LENGTH" ]
|
||||||
@ -282,7 +288,7 @@ function test_external_modification {
|
|||||||
echo "old" > ${TEST_TEXT_FILE}
|
echo "old" > ${TEST_TEXT_FILE}
|
||||||
OBJECT_NAME="$(basename $PWD)/${TEST_TEXT_FILE}"
|
OBJECT_NAME="$(basename $PWD)/${TEST_TEXT_FILE}"
|
||||||
sleep 2
|
sleep 2
|
||||||
echo "new new" | aws_cli cp - "s3://${TEST_BUCKET_1}/${OBJECT_NAME}"
|
echo "new new" | aws_cli s3 cp - "s3://${TEST_BUCKET_1}/${OBJECT_NAME}"
|
||||||
cmp ${TEST_TEXT_FILE} <(echo "new new")
|
cmp ${TEST_TEXT_FILE} <(echo "new new")
|
||||||
rm -f ${TEST_TEXT_FILE}
|
rm -f ${TEST_TEXT_FILE}
|
||||||
}
|
}
|
||||||
@ -291,7 +297,7 @@ function test_read_external_object() {
|
|||||||
describe "create objects via aws CLI and read via s3fs"
|
describe "create objects via aws CLI and read via s3fs"
|
||||||
OBJECT_NAME="$(basename $PWD)/${TEST_TEXT_FILE}"
|
OBJECT_NAME="$(basename $PWD)/${TEST_TEXT_FILE}"
|
||||||
sleep 3
|
sleep 3
|
||||||
echo "test" | aws_cli cp - "s3://${TEST_BUCKET_1}/${OBJECT_NAME}"
|
echo "test" | aws_cli s3 cp - "s3://${TEST_BUCKET_1}/${OBJECT_NAME}"
|
||||||
cmp ${TEST_TEXT_FILE} <(echo "test")
|
cmp ${TEST_TEXT_FILE} <(echo "test")
|
||||||
rm -f ${TEST_TEXT_FILE}
|
rm -f ${TEST_TEXT_FILE}
|
||||||
}
|
}
|
||||||
@ -343,6 +349,9 @@ function test_multipart_copy {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#check the renamed file content-type
|
||||||
|
check_content_type "$1/${BIG_FILE}-copy" "application/octet-stream"
|
||||||
|
|
||||||
rm -f "/tmp/${BIG_FILE}"
|
rm -f "/tmp/${BIG_FILE}"
|
||||||
rm_test_file "${BIG_FILE}-copy"
|
rm_test_file "${BIG_FILE}-copy"
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,8 @@ function cd_run_dir {
|
|||||||
echo "TEST_BUCKET_MOUNT_POINT variable not set"
|
echo "TEST_BUCKET_MOUNT_POINT variable not set"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
RUN_DIR=$(mktemp -d ${TEST_BUCKET_MOUNT_POINT_1}/testrun-XXXXXX)
|
RUN_DIR=${TEST_BUCKET_MOUNT_POINT_1}/${1}
|
||||||
|
mkdir -p ${RUN_DIR}
|
||||||
cd ${RUN_DIR}
|
cd ${RUN_DIR}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +192,8 @@ function describe {
|
|||||||
# made after the test run.
|
# made after the test run.
|
||||||
function run_suite {
|
function run_suite {
|
||||||
orig_dir=$PWD
|
orig_dir=$PWD
|
||||||
cd_run_dir
|
key_prefix="testrun-$RANDOM"
|
||||||
|
cd_run_dir $key_prefix
|
||||||
for t in "${TEST_LIST[@]}"; do
|
for t in "${TEST_LIST[@]}"; do
|
||||||
# The following sequence runs tests in a subshell to allow continuation
|
# The following sequence runs tests in a subshell to allow continuation
|
||||||
# on test failure, but still allowing errexit to be in effect during
|
# on test failure, but still allowing errexit to be in effect during
|
||||||
@ -202,7 +204,7 @@ function run_suite {
|
|||||||
# Other ways of trying to capture the return value will also disable
|
# Other ways of trying to capture the return value will also disable
|
||||||
# errexit in the function due to bash... compliance with POSIX?
|
# errexit in the function due to bash... compliance with POSIX?
|
||||||
set +o errexit
|
set +o errexit
|
||||||
(set -o errexit; $t)
|
(set -o errexit; $t $key_prefix)
|
||||||
if [[ $? == 0 ]]; then
|
if [[ $? == 0 ]]; then
|
||||||
report_pass $t
|
report_pass $t
|
||||||
else
|
else
|
||||||
@ -247,7 +249,15 @@ function get_mtime() {
|
|||||||
stat -c %Y "$1"
|
stat -c %Y "$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
function check_content_type() {
|
||||||
|
INFO_STR=`aws_cli s3api head-object --bucket ${TEST_BUCKET_1} --key $1`
|
||||||
|
if [[ "${INFO_STR}" != *"$2"* ]]
|
||||||
|
then
|
||||||
|
echo "moved file content-type is not as expected expected:$2 got:${INFO_STR}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function aws_cli() {
|
function aws_cli() {
|
||||||
AWS_ACCESS_KEY_ID=local-identity AWS_SECRET_ACCESS_KEY=local-credential aws s3 --endpoint-url "${S3_URL}" --no-verify-ssl $*
|
AWS_ACCESS_KEY_ID=local-identity AWS_SECRET_ACCESS_KEY=local-credential aws $* --endpoint-url "${S3_URL}" --no-verify-ssl
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user