Repository

Correctly handle symlinks

Parent commits : 6e34262cf7d74044ade6faf577396a4e709035a4,
Children commits :

By Laurent Defert on 2010-02-07 19:18:47
Correctly handle symlinks

Difference with parent commit 6e34262cf7d74044ade6faf577396a4e709035a4
Files modified:
conf-mirror
--- 
+++ 
@@ -42,36 +42,6 @@
 		dst = file[len(self.root) + 1:]
 		return path.join(self.dest, dst)
 
-class CreateLink(RecursiveFileHandler, MirroredDirs):
-	def __init__(self, root, dest):
-		RecursiveFileHandler.__init__(self, root)
-		MirroredDirs.__init__(self, root, dest)
-		self.dest = path.abspath(dest)
-
-	def HandleFile(self, file):
-		if self.IsHidden(file):
-			return
-		dst = self.GetDestination(file)
-		if path.islink(dst):
-			if readlink(dst) != file:
-				print "WARNING:", dst, "is a symlink pointing not pointing to mirror."
-				return
-			return
-		if path.exists(dst):
-			print "WARNING:", dst, "already exists."
-			return
-		symlink(file, dst)
-		print file, "->", dst
-
-	def HandleDir(self, file):
-		if self.IsHidden(file):
-			return
-		dst = self.GetDestination(file)
-		if path.exists(dst):
-			return
-		mkdir(dst)
-		print "new dir", dst
-
 class MoveOriginal(RecursiveFileHandler, MirroredDirs):
 	def __init__(self, root, dest):
 		RecursiveFileHandler.__init__(self, root)
@@ -83,7 +53,51 @@
 			return
 		dst = self.GetDestination(file)
 		print "moving file", file, "to", dst
+		if path.exists(dst):
+			print "WARNING:", dst, "already exists"
+			return
 		rename(file, dst)
+
+	def HandleLink(self, file):
+		if self.IsHidden(file):
+			return
+		dst = self.GetDestination(file)
+		if readlink(file) == dst:
+			return
+		if not path.isabs(readlink(file)):
+			print "WARNING:", file, "is a symlink to a relative path"
+			return
+		self.HandleFile(file)
+
+	def HandleDir(self, file):
+		if self.IsHidden(file):
+			return
+		dst = self.GetDestination(file)
+		if path.exists(dst):
+			return
+		mkdir(dst)
+		print "new dir", dst
+
+class CreateLink(RecursiveFileHandler, MirroredDirs):
+	def __init__(self, root, dest):
+		RecursiveFileHandler.__init__(self, root)
+		MirroredDirs.__init__(self, root, dest)
+		self.dest = path.abspath(dest)
+
+	def HandleFile(self, file):
+		if self.IsHidden(file):
+			return
+		dst = self.GetDestination(file)
+		if path.islink(dst) and readlink(dst) == file:
+			return
+		if path.exists(dst):
+			print "WARNING:", dst, "already exists."
+			return
+		symlink(file, dst)
+		print file, "->", dst
+
+	def HandleLink(self, file):
+		self.HandleFile(file)
 
 	def HandleDir(self, file):
 		if self.IsHidden(file):