git » pygen » commit 148d7eb

Improve directory mtime preservation.

author Alberto Bertogli
2006-03-07 17:56:21 UTC
committer Alberto Bertogli
2006-03-07 17:56:21 UTC
parent 03dd278a118db2a4bf4404e4d153f640e4d7e77d

Improve directory mtime preservation.

pygen +8 -8

diff --git a/pygen b/pygen
index 52beb5e..e6aa589 100644
--- a/pygen
+++ b/pygen
@@ -118,6 +118,10 @@ def autogen(src, dst):
 		print 'mkdir', dst
 		os.mkdir(dst)
 
+	# directories' stats must be updated after we do all the generation,
+	# so we append them to the list as we go
+	to_update_stat = []
+
 	for path, dirs, files in tree:
 		for d in dirs:
 			fulld = path + '/' + d
@@ -129,6 +133,7 @@ def autogen(src, dst):
 			if not os.path.isdir(p):
 				print 'mkdir', p
 				os.mkdir(p)
+				to_update_stat.append((fulld, p))
 
 		for f in files:
 			fullf = path + '/' + f
@@ -160,14 +165,9 @@ def autogen(src, dst):
 					shutil.copy2(fullf, t)
 
 	# second pass to preserve directories' modification time
-	tree = os.walk(srcroot)
-	for path, dirs, files in tree:
-		for d in dirs:
-			fulld = path + '/' + d
-			diff = fulld[len(srcroot):]
-			p = os.path.normpath(dst + '/' + diff)
-			print 'copystat', p
-			shutil.copystat(fulld, p)
+	for s, d in to_update_stat:
+			print 'copystat', d
+			shutil.copystat(s, d)
 
 
 if __name__ == '__main__':