Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmpfiles.py: fixed symlink creation (fixes #40) #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions init/tmpfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ class SymlinkCreate(Action):
"""L - create symlink"""

def apply_one(self, path):
if not os.path.exists(path):
# only create symlink if it does not exists yet
# don't care about existing but broken links
if not os.path.exists(path) and not os.path.islink(path):
if self.arg is None:
# TODO link to /usr/share/factory/FILE
# (see tmpfiles.d(5) for details)
Expand All @@ -511,10 +513,14 @@ class SymlinkRecreate(SymlinkCreate):
"""L+ - [re]create symlink"""

def apply_one(self, path):
if os.path.exists(path):
# need to detect if path is broken link, because
# os.path.exists returns False for broken symbolic links
if os.path.exists(path) or os.path.islink(path):
if not os.path.islink(path) and os.path.isdir(path):
# remove directory with all its content
shutil.rmtree(path)
else:
# remove existing file or link (but not target file)
os.unlink(path)
super().apply(path)

Expand Down