Skip to content

Commit

Permalink
2007-11-12 Michal Ludvig <michal@logix.cz>
Browse files Browse the repository at this point in the history
	* s3cmd: Support for storing file attributes (like ownership, 
	  mode, etc) in sync operation.



git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@153 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information
mludvig committed Nov 12, 2007
1 parent 0357579 commit a368faf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2007-11-12 Michal Ludvig <michal@logix.cz>

* s3cmd: Support for storing file attributes (like ownership,
mode, etc) in sync operation.

2007-10-01 Michal Ludvig <michal@logix.cz>

* s3cmd: Fix typo in argument name (patch
Expand Down
12 changes: 12 additions & 0 deletions S3/Config.py
Expand Up @@ -23,6 +23,18 @@ class Config(object):
proxy_host = ""
proxy_port = 3128
encrypt = False
dry_run = False
preserve_attrs = True
preserve_attrs_list = [
'uname', # Verbose owner Name (e.g. 'root')
#'uid', # Numeric user ID (e.g. 0)
'gname', # Group name (e.g. 'users')
#'gid', # Numeric group ID (e.g. 100)
'mtime', # Modification timestamp
'ctime', # Creation timestamp
'mode', # File mode (e.g. rwxr-xr-x = 755)
#'acl', # Full ACL (not yet supported)
]
delete_removed = False
_doc['delete_removed'] = "[sync] Remove remote S3 objects when local file has been deleted"
gpg_passphrase = ""
Expand Down
29 changes: 26 additions & 3 deletions s3cmd
Expand Up @@ -11,6 +11,7 @@ import time
import os
import re
import errno
import pwd, grp

from copy import copy
from optparse import OptionParser, Option, OptionValueError, IndentedHelpFormatter
Expand Down Expand Up @@ -262,6 +263,20 @@ def cmd_object_del(args):
output("Object %s deleted" % uri)

def cmd_sync(args):
def _build_attr_header(src):
attrs = {}
st = os.stat_result(os.stat(src))
for attr in cfg.preserve_attrs_list:
if attr == 'uname':
val = pwd.getpwuid(st.st_uid).pw_name
elif attr == 'gname':
val = grp.getgrgid(st.st_gid).gr_name
else:
val = getattr(st, 'st_' + attr)
attrs[attr] = val
result = ""
for k in attrs: result += "%s:%s/" % (k, attrs[k])
return { 'x-amz-meta-s3cmd-attrs' : result[:-1] }
src = args.pop(0)
if S3Uri(src).type != "file":
raise ParameterError("Source must be a local path instead of: %s" % src)
Expand All @@ -277,10 +292,15 @@ def cmd_sync(args):
s3 = S3(Config())

output("Compiling list of local files...")
loc_base = os.path.join(src, "")
if os.path.isdir(src):
loc_base = os.path.join(src, "")
filelist = os.walk(src)
else:
loc_base = "./"
filelist = [( '.', [], [src] )]
loc_base_len = len(loc_base)
loc_list = {}
for root, dirs, files in os.walk(src):
for root, dirs, files in filelist:
## TODO: implement explicit exclude
for f in files:
full_name = os.path.join(root, f)
Expand Down Expand Up @@ -362,7 +382,10 @@ def cmd_sync(args):
seq += 1
src = loc_list[file]['full_name']
uri = S3Uri(dst_base + file)
response = s3.object_put_uri(src, uri)
if cfg.preserve_attrs:
attr_header = _build_attr_header(src)
debug(attr_header)
response = s3.object_put_uri(src, uri, attr_header)
output("stored '%s' as '%s' (%d bytes) [%d of %d]" % (src, uri, response["size"], seq, total_count))
total_size += response["size"]
output("Done. Uploaded %d bytes." % total_size)
Expand Down

0 comments on commit a368faf

Please sign in to comment.