mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-09 22:30:57 +00:00
Fixed issue #72 - rsync to s3fs mount defaults to application/octet-stream
Applied supplied patch. The patch solves this issue by modifying the lookupMimeType function to not only analyze the last extension for a matching mime type, but analyze the second to last extension if the last extension did not result in a match. git-svn-id: http://s3fs.googlecode.com/svn/trunk@198 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
parent
b792abb702
commit
7a9ddf4df4
@ -908,13 +908,57 @@ static mimes_t mimeTypes;
|
||||
string
|
||||
lookupMimeType(string s) {
|
||||
string result("application/octet-stream");
|
||||
string::size_type pos = s.find_last_of('.');
|
||||
if (pos != string::npos) {
|
||||
s = s.substr(1+pos, string::npos);
|
||||
string::size_type last_pos = s.find_last_of('.');
|
||||
string::size_type first_pos = s.find_first_of('.');
|
||||
string prefix, ext, ext2;
|
||||
|
||||
// No dots in name, just return
|
||||
if (last_pos == string::npos) {
|
||||
return result;
|
||||
}
|
||||
mimes_t::const_iterator iter = mimeTypes.find(s);
|
||||
if (iter != mimeTypes.end())
|
||||
|
||||
// extract the last extension
|
||||
if (last_pos != string::npos) {
|
||||
ext = s.substr(1+last_pos, string::npos);
|
||||
}
|
||||
|
||||
|
||||
if (last_pos != string::npos) {
|
||||
// one dot was found, now look for another
|
||||
if (first_pos != string::npos && first_pos < last_pos) {
|
||||
prefix = s.substr(0, last_pos);
|
||||
// Now get the second to last file extension
|
||||
string::size_type next_pos = prefix.find_last_of('.');
|
||||
if (next_pos != string::npos) {
|
||||
ext2 = prefix.substr(1+next_pos, string::npos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we get here, then we have an extension (ext)
|
||||
mimes_t::const_iterator iter = mimeTypes.find(ext);
|
||||
// if the last extension matches a mimeType, then return
|
||||
// that mime type
|
||||
if (iter != mimeTypes.end()) {
|
||||
result = (*iter).second;
|
||||
return result;
|
||||
}
|
||||
|
||||
// return with the default result if there isn't a second extension
|
||||
if (first_pos == last_pos) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Didn't find a mime-type for the first extension
|
||||
// Look for second extension in mimeTypes, return if found
|
||||
iter = mimeTypes.find(ext2);
|
||||
if (iter != mimeTypes.end()) {
|
||||
result = (*iter).second;
|
||||
return result;
|
||||
}
|
||||
|
||||
// neither the last extension nor the second-to-last extension
|
||||
// matched a mimeType, return the default mime type
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user