mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
os.misc: Add update_symlink()
update_symlink(target, link_name) does the equivalent of ln -sf, i.e. force replacement of link_name with a new sysmlink, if it existed before the call. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
a4fb791649
commit
12bf59b3cd
1 changed files with 10 additions and 0 deletions
|
|
@ -19,6 +19,16 @@ def silentremove(filename): #export
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise # re-raise exception if a different error occurred
|
raise # re-raise exception if a different error occurred
|
||||||
|
|
||||||
|
def update_symlink(target, link_name):
|
||||||
|
try:
|
||||||
|
os.symlink(target, link_name)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno == errno.EEXIST:
|
||||||
|
os.remove(link_name)
|
||||||
|
os.symlink(target, link_name)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
def pad(token: str, total_size: int, right_align: bool = False) -> str:
|
def pad(token: str, total_size: int, right_align: bool = False) -> str:
|
||||||
add = total_size - len(token)
|
add = total_size - len(token)
|
||||||
if add <= 0:
|
if add <= 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue