[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] Remove v3bw file link if it exist



commit 75c37b818138d74ce5174dad4112619b797375ed
Author: juga0 <juga@xxxxxxxxxx>
Date:   Thu Jun 14 16:30:54 2018 +0000

    Remove v3bw file link if it exist
    
    also fix link path
---
 sbws/lib/v3bwfile.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 1294d99..40a8fd5 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -402,14 +402,21 @@ class V3BwFile(object):
 
     def write(self, output):
         log.info('Writing v3bw file to %s', output)
+        out_dir = os.path.dirname(output)
+        out_link = os.path.join(out_dir, 'latest.v3bw')
+        if os.path.exists(out_link):
+            log.debug('Deleting existing symlink before creating a new one.')
+            os.remove(out_link)
         # to keep test_generate.py working
         if output != '/dev/stdout':
-            with DirectoryLock(os.path.dirname(output)):
+            with DirectoryLock(out_dir):
                 with open(output, 'wt') as fd:
                     fd.write(str(self.header))
                     for line in self.bw_lines:
                         fd.write(str(line))
-                os.symlink(output, 'latest.v3bw')
+                log.debug('Creating symlink from {} to {}.'
+                          .format(output, out_link))
+                os.symlink(output, out_link)
         else:
             with open(output, 'wt') as fd:
                 fd.write(str(self.header))



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits