From 3a581ef75ccd693625905a2fe468a3a80d5ef933 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Mon, 2 Mar 2020 10:00:00 +0100
Subject: [PATCH] Improve symlink handling. Add missing import of shutil.

---
 secondary.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/secondary.py b/secondary.py
index e2128f7..d5a1dd5 100644
--- a/secondary.py
+++ b/secondary.py
@@ -8,6 +8,7 @@ import os
 import socket
 import subprocess
 import time
+import shutil
 
 def cond_unlink(path, log):
     try:
@@ -88,10 +89,11 @@ class Backup:
                                dst.uid, dst.gid)
                 os.lchown(dst_path, int(src.uid), int(src.gid))
                 changed = True
-            if src.kind == b'F' and src.mtime != dst.mtime:
+            if src.kind in [ b'F', b'L' ] and src.mtime != dst.mtime:
                 self.log.DEBUG('MTIME', src.name, src.mtime, dst.mtime)
-                atime = os.stat(dst_path).st_atime
-                os.utime(dst_path, (int(atime), int(src.mtime)))
+                atime = os.lstat(dst_path).st_atime
+                os.utime(dst_path, (int(atime), int(src.mtime)),
+                         follow_symlinks=False)
                 changed = True
             if changed:
                 self.status.metadata += 1
-- 
GitLab