git » abk » commit d3e2822

Check paths before copying.

author
2005-03-02 18:42:09 UTC
committer
2005-03-02 18:42:09 UTC
parent 1e629a87f64593fab90a2c44b3891581da728e64

Check paths before copying.
Make sure the path to a file exists before copying it. It's useful for
incremental backups where the destination hierachy might be empty (and, of
course, differ from the destination index).

abk +13 -0

diff --git a/abk b/abk
index 383145e..ddca6de 100644
--- a/abk
+++ b/abk
@@ -157,6 +157,10 @@ class file_info:
 
 	def copy_file(self, dst):
 		"Copies a file, along with its permissions and ownership."
+		# create the path to dst if it doesn't exist
+		make_path(dst)
+
+		# copy accordingly to the file type
 		if self.type == 'r':
 			self.copy_file_reg(dst)
 		elif self.type == 'l':
@@ -281,6 +285,15 @@ def force_unlink(path, type):
 		except OSError:
 			pass
 
+def make_path(f):
+	"If f is 'a/b/c/f', make sure 'a/b/c' exist."
+	dir = os.path.dirname(f)
+	try:
+		os.makedirs(dir)
+	except OSError:
+		# it can fail if already exist
+		pass
+
 #
 # main
 #