From 0ba8cd41deb150293b70c0965af7f6c8cf8eb571 Mon Sep 17 00:00:00 2001 From: Andreas Schleifer Date: Tue, 28 Nov 2023 17:20:59 +0100 Subject: [PATCH] feat(tools): handle symlinks correctly for take command (#240) --- nvchecker/tools.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nvchecker/tools.py b/nvchecker/tools.py index 0c6b615..5e43b5d 100644 --- a/nvchecker/tools.py +++ b/nvchecker/tools.py @@ -4,8 +4,10 @@ import sys import argparse +import shutil import structlog import json +import os.path from . import core @@ -60,9 +62,12 @@ def take() -> None: sys.exit(2) try: - oldverf.rename( - oldverf.with_name(oldverf.name + '~'), - ) + if os.path.islink(oldverf): + shutil.copy(oldverf, oldverf.with_name(oldverf.name + '~')) + else: + oldverf.rename( + oldverf.with_name(oldverf.name + '~'), + ) except FileNotFoundError: pass core.write_verfile(oldverf, oldvers)