Browse code

* S3/Config.py: Store more file attributes in sync to S3. * s3cmd: Make sync remote2local more error-resilient.

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@182 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2008/06/04 21:11:04
Showing 4 changed files
... ...
@@ -1,3 +1,8 @@
1
+2008-06-05  Michal Ludvig  <michal@logix.cz>
2
+
3
+	* S3/Config.py: Store more file attributes in sync to S3.
4
+	* s3cmd: Make sync remote2local more error-resilient.
5
+
1 6
 2008-06-04  Michal Ludvig  <michal@logix.cz>
2 7
 
3 8
 	* s3cmd: Implemented cmd_sync_remote2local() for restoring
... ...
@@ -29,9 +29,10 @@ class Config(object):
29 29
 	preserve_attrs = True
30 30
 	preserve_attrs_list = [ 
31 31
 		'uname',	# Verbose owner Name (e.g. 'root')
32
-		#'uid',		# Numeric user ID (e.g. 0)
32
+		'uid',		# Numeric user ID (e.g. 0)
33 33
 		'gname',	# Group name (e.g. 'users')
34
-		#'gid',		# Numeric group ID (e.g. 100)
34
+		'gid',		# Numeric group ID (e.g. 100)
35
+		'atime',	# Last access timestamp
35 36
 		'mtime',	# Modification timestamp
36 37
 		'ctime',	# Creation timestamp
37 38
 		'mode',		# File mode (e.g. rwxr-xr-x = 755)
... ...
@@ -143,9 +143,9 @@ def hash_file_md5(filename):
143 143
 	f.close()
144 144
 	return h.hexdigest()
145 145
 
146
-def mkdir_with_parents(dir_name, mode):
146
+def mkdir_with_parents(dir_name):
147 147
 	"""
148
-	mkdir_with_parents(dst_dir, mode)
148
+	mkdir_with_parents(dst_dir)
149 149
 	
150 150
 	Create directory 'dir_name' with all parent directories
151 151
 
... ...
@@ -161,10 +161,10 @@ def mkdir_with_parents(dir_name, mode):
161 161
 		try:
162 162
 			debug("mkdir(%s)" % cur_dir)
163 163
 			os.mkdir(cur_dir)
164
-		except IOError, e:
165
-			error("%s: can not make directory: %s" % (cur_dir, e.strerror))
164
+		except (OSError, IOError), e:
165
+			warning("%s: can not make directory: %s" % (cur_dir, e.strerror))
166 166
 			return False
167 167
 		except Exception, e:
168
-			error("%s: %s" % (cur_dir, e))
168
+			warning("%s: %s" % (cur_dir, e))
169 169
 			return False
170 170
 	return True
... ...
@@ -441,7 +441,7 @@ def cmd_sync_remote2local(src, dst):
441 441
 		try:
442 442
 			dst_dir = os.path.dirname(dst_file)
443 443
 			if not dir_cache.has_key(dst_dir):
444
-				dir_cache[dst_dir] = Utils.mkdir_with_parents(dst_dir, mode = 022)
444
+				dir_cache[dst_dir] = Utils.mkdir_with_parents(dst_dir)
445 445
 			if dir_cache[dst_dir] == False:
446 446
 				warning("%s: destination directory not writable: %s" % (file, dst_dir))
447 447
 				continue
... ...
@@ -463,14 +463,20 @@ def cmd_sync_remote2local(src, dst):
463 463
 					attrs = _parse_attrs_header(response['headers']['x-amz-meta-s3cmd-attrs'])
464 464
 					if attrs.has_key('mode'):
465 465
 						os.chmod(dst_file, int(attrs['mode']))
466
-					## FIXME: uid/gid and mtime/ctime handling comes here! TODO
466
+					if attrs.has_key('mtime') or attrs.has_key('atime'):
467
+						mtime = attrs.has_key('mtime') and int(attrs['mtime']) or int(time.time())
468
+						atime = attrs.has_key('atime') and int(attrs['atime']) or int(time.time())
469
+						os.utime(dst_file, (atime, mtime))
470
+					## FIXME: uid/gid / uname/gname handling comes here! TODO
467 471
 			except OSError, e:
468 472
 				if e.errno == errno.EEXIST:
469 473
 					warning("%s exists - not overwriting" % (dst_file))
470 474
 					continue
475
+				if e.errno in (errno.EPERM, errno.EACCES):
476
+					warning("%s not writable: %s" % (dst_file, e.strerror))
477
+					continue
471 478
 				raise
472
-			except IOError, e:
473
-				## See if it's missing path and try again
479
+			except Exception, e:
474 480
 				error("%s: %s" % (file, e))
475 481
 				continue
476 482
 			finally: