Skip to content

Fix wallpaper-restore.sh: safe ~ expansion, handle spaces, add robustness checks#1462

Open
rajghosh06-dev wants to merge 1 commit intomylinuxforwork:mainfrom
rajghosh06-dev:fix-wallpaper-restore
Open

Fix wallpaper-restore.sh: safe ~ expansion, handle spaces, add robustness checks#1462
rajghosh06-dev wants to merge 1 commit intomylinuxforwork:mainfrom
rajghosh06-dev:fix-wallpaper-restore

Conversation

@rajghosh06-dev
Copy link

Fix wallpaper-restore.sh: safe ~ expansion, handle spaces, add robustness checks (to ~ path)

This PR improves wallpaper-restore.sh by:

  • Replacing sed-based ~ expansion with safe handling (only expands leading ~).
  • Adding quotes around variables to support paths with spaces.
  • Using realpath -m to normalize paths.
  • Adding guards for empty cache entries, relative paths, broken symlinks, and non-image files.

Tested with (following in local machine)

  • ~/Pictures/... paths → expands correctly
  • /home/user/Pictures/... absolute paths → untouched
  • Paths containing spaces (e.g., Holiday Photos) → handled safely
  • Empty or malformed cache entries → falls back to default
  • Broken symlinks → falls back to default
  • Non-image files (e.g., accidentally cached .txt) → rejected, default used

This prevents corrupted paths and ensures wallpapers are restored reliably across different setups.


Checklist for Reviewing

  • Verified safe handling of ~ expansion
  • Confirmed quoted variables prevent issues with spaces
  • Tested normalization with realpath -m
  • Checked fallback behavior for empty cache entries
  • Confirmed handling of relative paths
  • Validated broken symlink detection
  • Ensured non-image files are rejected gracefully
  • Confirmed default wallpaper is used when needed

Before vs After

Aspect Before (Old Script) After (Improved Script)
~ expansion Used sed -i (risk of corrupting folder names) Safe expansion only at start of path
Handling spaces in paths Unquoted variables → broke on spaces All variables quoted → spaces handled safely
Path normalization None realpath -m ensures canonical, valid paths
Empty cache entries Not handled Guard added → falls back to default
Relative paths Could slip through Enforced absolute paths only
Symlink handling Not checked Detects broken symlinks → falls back
File type validation Any file accepted Only valid image extensions allowed
Default fallback Limited checks Robust fallback in all failure cases

Note to Maintainers:

Thank you for reviewing this contribution. The changes are focused on improving reliability and robustness without altering existing functionality. I appreciate your time and feedback, and I’m happy to make any adjustments if needed.

@rajghosh06-dev
Copy link
Author

Related/Similar Issues:

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

Successfully merging this pull request may close these issues.

1 participant