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

Behavior when persisting files #197

Open
karaolidis opened this issue Jul 31, 2024 · 2 comments
Open

Behavior when persisting files #197

karaolidis opened this issue Jul 31, 2024 · 2 comments

Comments

@karaolidis
Copy link

The README says: "If the file exists in persistent storage, it will be bind mounted to the target path; otherwise it will be symlinked."

Is there a specific reason for this behavior that I am missing out on? In my use case, some files spot the broken symlink, delete it, and replace it with their own file that ends up not being persisted. Wouldn't it make more sense to do:

...

if [[ -L "$mountPoint" && $(readlink -f "$mountPoint") == "$targetFile" ]]; then
    trace "$mountPoint already links to $targetFile, ignoring"
elif mount | grep -F "$mountPoint"' ' >/dev/null && ! mount | grep -F "$mountPoint"/ >/dev/null; then
    trace "mount already exists at $mountPoint, ignoring"
elif [[ -e "$mountPoint" ]]; then
    echo "A file already exists at $mountPoint!" >&2
    exit 1
fi

if [[ ! -e "$targetFile" ]]; then
    touch "$targetFile"
fi

touch "$mountPoint"
mount -o bind "$targetFile" "$mountPoint"

Instead of:

...

if [[ -L "$mountPoint" && $(readlink -f "$mountPoint") == "$targetFile" ]]; then
    trace "$mountPoint already links to $targetFile, ignoring"
elif mount | grep -F "$mountPoint"' ' >/dev/null && ! mount | grep -F "$mountPoint"/ >/dev/null; then
    trace "mount already exists at $mountPoint, ignoring"
elif [[ -e "$mountPoint" ]]; then
    echo "A file already exists at $mountPoint!" >&2
    exit 1
elif [[ -e "$targetFile" ]]; then
    touch "$mountPoint"
    mount -o bind "$targetFile" "$mountPoint"
else
    ln -s "$targetFile" "$mountPoint"
fi

I can open a PR if so :)

Thanks.

@karaolidis
Copy link
Author

Just had a read through #1, I think adding an option to specify the behavior when a file doesn't exist might be a good call?

@nazarewk
Copy link

nazarewk commented Aug 2, 2024

I'm actually hitting an issue related to this behavior: a lot of software seems to replace symlink with raw files preventing those from being stored at all.

I could really use an option to specify the default content of the file if it doesn't exist in either place so it is ALWAYS bind-mounted.

Another option would be to create a oneshot .service triggered by a PathExists= to move the file into /persist and create bind mount as soon as it appears for the first time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants