[packages/s3fs] Fix handling files with no x-amz-meta-mode
jajcus
jajcus at pld-linux.org
Thu Jan 3 10:21:34 CET 2013
commit 6334f526bff9c0e3b70afe9b3e02bfa785d36a70
Author: Jacek Konieczny <j.konieczny at eggsoft.pl>
Date: Thu Jan 3 10:14:56 2013 +0100
Fix handling files with no x-amz-meta-mode
use_cache= option would not work for S3 files with not meta-data
attached and retrieved files modes would be 000.
s3fs-missing_mode.patch | 15 +++++
s3fs-x-amz-meta.patch | 153 ++++++++++++++++++++++++++++++++++++++++++++++++
s3fs.spec | 4 ++
3 files changed, 172 insertions(+)
---
diff --git a/s3fs.spec b/s3fs.spec
index 1aad41f..000ee73 100644
--- a/s3fs.spec
+++ b/s3fs.spec
@@ -7,6 +7,8 @@ License: GPL v2
Group: Applications/System
Source0: http://s3fs.googlecode.com/files/%{name}-%{version}.tar.gz
# Source0-md5: 0dd7b7e9b1c58312cde19894488c5072
+Patch0: %{name}-x-amz-meta.patch
+Patch1: %{name}-missing_mode.patch
URL: http://code.google.com/p/s3fs/wiki/FuseOverAmazon
BuildRequires: curl-devel
BuildRequires: libfuse-devel
@@ -27,6 +29,8 @@ e.g., rsync backup to s3.
%prep
%setup -q
+%patch0 -p0
+%patch1 -p1
%build
%configure
diff --git a/s3fs-missing_mode.patch b/s3fs-missing_mode.patch
new file mode 100644
index 0000000..d7f256d
--- /dev/null
+++ b/s3fs-missing_mode.patch
@@ -0,0 +1,15 @@
+diff -dur s3fs-1.61.orig/src/s3fs.cpp s3fs-1.61/src/s3fs.cpp
+--- s3fs-1.61.orig/src/s3fs.cpp 2013-01-03 10:05:41.000000000 +0100
++++ s3fs-1.61/src/s3fs.cpp 2013-01-03 10:05:28.000000000 +0100
+@@ -126,7 +126,10 @@
+ }
+
+ mode_t get_mode(const char *s) {
+- return (mode_t) strtoul(s, (char **) NULL, 10);
++ if (s && *s)
++ return (mode_t) strtoul(s, (char **) NULL, 10);
++ else
++ return (mode_t) S_IFREG | 0644;
+ }
+
+ uid_t get_uid(const char *s) {
diff --git a/s3fs-x-amz-meta.patch b/s3fs-x-amz-meta.patch
new file mode 100644
index 0000000..eea779b
--- /dev/null
+++ b/s3fs-x-amz-meta.patch
@@ -0,0 +1,153 @@
+http://code.google.com/p/s3fs/source/detail?r=376
+
+Index: src/s3fs.cpp
+===================================================================
+--- src/s3fs.cpp (revision 375)
++++ src/s3fs.cpp (revision 376)
+@@ -121,6 +121,22 @@
+ headMap_t headMap;
+ };
+
++time_t get_mtime(const char *s) {
++ return (time_t) strtoul(s, (char **) NULL, 10);
++}
++
++mode_t get_mode(const char *s) {
++ return (mode_t) strtoul(s, (char **) NULL, 10);
++}
++
++uid_t get_uid(const char *s) {
++ return (uid_t) strtoul(s, (char **) NULL, 10);
++}
++
++gid_t get_gid(const char *s) {
++ return (gid_t) strtoul(s, (char **) NULL, 10);
++}
++
+ static int insert_object(char *name, struct s3_object **head) {
+ size_t n_len = strlen(name) + 1;
+ struct s3_object *new_object;
+@@ -527,7 +543,7 @@
+
+ // need to download?
+ if(fd == -1) {
+- mode_t mode = strtoul(responseHeaders["x-amz-meta-mode"].c_str(), (char **)NULL, 10);
++ mode_t mode = get_mode(responseHeaders["x-amz-meta-mode"].c_str());
+
+ if(use_cache.size() > 0) {
+ // only download files, not folders
+@@ -589,7 +605,7 @@
+ if(use_cache.size() > 0 && !S_ISLNK(mode)) {
+ // make the file's mtime match that of the file on s3
+ struct utimbuf n_mtime;
+- n_mtime.modtime = strtoul(responseHeaders["x-amz-meta-mtime"].c_str(), (char **) NULL, 10);
++ n_mtime.modtime = get_mtime(responseHeaders["x-amz-meta-mtime"].c_str());
+ n_mtime.actime = n_mtime.modtime;
+ if((utime(cache_path.c_str(), &n_mtime)) == -1) {
+ YIKES(-errno);
+@@ -691,7 +707,7 @@
+ string cache_path(use_cache + "/" + bucket + path);
+
+ if((stat(cache_path.c_str(), &st)) == 0) {
+- n_mtime.modtime = strtoul(meta["x-amz-meta-mtime"].c_str(), (char **) NULL, 10);
++ n_mtime.modtime = get_mtime(meta["x-amz-meta-mtime"].c_str());
+ n_mtime.actime = n_mtime.modtime;
+ if((utime(cache_path.c_str(), &n_mtime)) == -1) {
+ YIKES(-errno);
+@@ -763,7 +779,7 @@
+ string cache_path(use_cache + "/" + bucket + path);
+
+ if((stat(cache_path.c_str(), &st)) == 0) {
+- n_mtime.modtime = strtoul(meta["x-amz-meta-mtime"].c_str(), (char **) NULL, 10);
++ n_mtime.modtime = get_mtime(meta["x-amz-meta-mtime"].c_str());
+ n_mtime.actime = n_mtime.modtime;
+ if((utime(cache_path.c_str(), &n_mtime)) == -1) {
+ YIKES(-errno);
+@@ -1579,14 +1595,14 @@
+
+ stbuf->st_nlink = 1; // see fuse faq
+
+- stbuf->st_mtime = strtoul(responseHeaders["x-amz-meta-mtime"].c_str(), (char **)NULL, 10);
++ stbuf->st_mtime = get_mtime(responseHeaders["x-amz-meta-mtime"].c_str());
+ if (stbuf->st_mtime == 0) {
+ long LastModified;
+ if (curl_easy_getinfo(curl, CURLINFO_FILETIME, &LastModified) == 0)
+ stbuf->st_mtime = LastModified;
+ }
+
+- stbuf->st_mode = strtoul(responseHeaders["x-amz-meta-mode"].c_str(), (char **)NULL, 10);
++ stbuf->st_mode = get_mode(responseHeaders["x-amz-meta-mode"].c_str());
+ char* ContentType = 0;
+ if (curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ContentType) == 0) {
+ if (ContentType)
+@@ -1600,8 +1616,8 @@
+ if (S_ISREG(stbuf->st_mode))
+ stbuf->st_blocks = stbuf->st_size / 512 + 1;
+
+- stbuf->st_uid = strtoul(responseHeaders["x-amz-meta-uid"].c_str(), (char **)NULL, 10);
+- stbuf->st_gid = strtoul(responseHeaders["x-amz-meta-gid"].c_str(), (char **)NULL, 10);
++ stbuf->st_uid = get_uid(responseHeaders["x-amz-meta-uid"].c_str());
++ stbuf->st_gid = get_gid(responseHeaders["x-amz-meta-gid"].c_str());
+
+ // update stat cache
+ add_stat_cache_entry(path, stbuf);
+@@ -2649,7 +2665,7 @@
+ string cache_path(use_cache + "/" + bucket + path);
+
+ if((stat(cache_path.c_str(), &st)) == 0) {
+- n_mtime.modtime = strtoul(meta["x-amz-meta-mtime"].c_str(), (char **) NULL, 10);
++ n_mtime.modtime = get_mtime(meta["x-amz-meta-mtime"].c_str());
+ n_mtime.actime = n_mtime.modtime;
+ if((utime(cache_path.c_str(), &n_mtime)) == -1) {
+ YIKES(-errno);
+@@ -2852,8 +2868,7 @@
+ st.st_nlink = 1; // see fuse FAQ
+
+ // mode
+- st.st_mode = strtoul(
+- (*response.responseHeaders)["x-amz-meta-mode"].c_str(), (char **)NULL, 10);
++ st.st_mode = get_mode((*response.responseHeaders)["x-amz-meta-mode"].c_str());
+
+ // content-type
+ char *ContentType = 0;
+@@ -2862,7 +2877,7 @@
+ st.st_mode |= strcmp(ContentType, "application/x-directory") == 0 ? S_IFDIR : S_IFREG;
+
+ // mtime
+- st.st_mtime = strtoul((*response.responseHeaders)["x-amz-meta-mtime"].c_str(), (char **)NULL, 10);
++ st.st_mtime = get_mtime((*response.responseHeaders)["x-amz-meta-mtime"].c_str());
+ if(st.st_mtime == 0) {
+ long LastModified;
+ if(curl_easy_getinfo(curl_handle, CURLINFO_FILETIME, &LastModified) == 0)
+@@ -2878,8 +2893,8 @@
+ if(S_ISREG(st.st_mode))
+ st.st_blocks = st.st_size / 512 + 1;
+
+- st.st_uid = strtoul((*response.responseHeaders)["x-amz-meta-uid"].c_str(), (char **)NULL, 10);
+- st.st_gid = strtoul((*response.responseHeaders)["x-amz-meta-gid"].c_str(), (char **)NULL, 10);
++ st.st_uid = get_uid((*response.responseHeaders)["x-amz-meta-uid"].c_str());
++ st.st_gid = get_gid((*response.responseHeaders)["x-amz-meta-gid"].c_str());
+
+ add_stat_cache_entry(response.path.c_str(), &st);
+
+@@ -3145,7 +3160,7 @@
+ }
+
+ struct stat stbuf;
+- stbuf.st_mode = strtoul(responseHeaders["x-amz-meta-mode"].c_str(), (char **)NULL, 10);
++ stbuf.st_mode = get_mode(responseHeaders["x-amz-meta-mode"].c_str());
+ char* ContentType = 0;
+ if(curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ContentType) == 0)
+ if(ContentType)
+Index: src/s3fs.h
+===================================================================
+--- src/s3fs.h (revision 375)
++++ src/s3fs.h (revision 376)
+@@ -94,6 +94,7 @@
+ std::string md5sum(int fd);
+ char *get_realpath(const char *path);
+
++time_t get_mtime(const char *s);
+ static int insert_object(char *name, struct s3_object **head);
+ static unsigned int count_object_list(struct s3_object *list);
+ static int free_object(struct s3_object *object);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/s3fs.git/commitdiff/60a3f1e3f8a159e77048ab70d6119d36dcdb675f
More information about the pld-cvs-commit
mailing list