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

Update mounted check to support symlink paths #130

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.

## Unreleased

- Support use of symlinks for device paths

## 4.0.14 - *2024-05-03*

- Update tested platforms
Expand Down
13 changes: 12 additions & 1 deletion libraries/fs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ module FilesystemMod

# Check to determine if the device is mounted.
def mounted?(device)
shell_out("grep -q '#{device}' /proc/mounts").exitstatus != 0 ? nil : shell_out("grep -q '#{device}' /proc/mounts").exitstatus
device_path = device
unless File.exist?(device)
# Returning nil on missing file because it sure isn't mounted.
return
end

# If the device is a symlink the real path is obtained so the check on /proc/mounts is valid.
if File.symlink?(device)
device_path = File.realpath(device)
end

shell_out("grep -q '#{device_path}' /proc/mounts").exitstatus != 0 ? nil : shell_out("grep -q '#{device_path}' /proc/mounts").exitstatus
end

# Check to determine if the mount is frozen.
Expand Down
Loading