mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2025-02-02 11:58:28 +00:00
fix read-only opening of tombs using -o ro
skip touch, chown and some minor operations when read-only
This commit is contained in:
parent
fb3ffcec03
commit
7f2e22c517
37
tomb
37
tomb
@ -124,8 +124,10 @@ $msg
|
||||
# Cleanup anything sensitive before exiting.
|
||||
_endgame() {
|
||||
|
||||
option_value_contains -o ro || {
|
||||
# Restore access time of sensitive files
|
||||
[[ -z $TOMBFILESSTAT ]] || _restore_stat
|
||||
}
|
||||
|
||||
# Prepare some random material to overwrite vars
|
||||
local rr="$RANDOM"
|
||||
@ -537,10 +539,12 @@ is_valid_tomb() {
|
||||
local _fail=0
|
||||
# Tomb file must be a readable, writable, non-empty regular file.
|
||||
# If passed the "ro" mount option, the writable check is skipped.
|
||||
[[ ! -w "$1" ]] && [[ $(option_value -o) != *"ro"* ]] && {
|
||||
option_value_contains -o ro || {
|
||||
[[ ! -w "$1" ]] && {
|
||||
_warning "Tomb file is not writable: ::1 tomb file::" $1
|
||||
_fail=1
|
||||
}
|
||||
}
|
||||
_verbose "tomb file is readable"
|
||||
|
||||
[[ ! -f "$1" ]] && {
|
||||
@ -755,6 +759,16 @@ option_value() {
|
||||
print -n - "${OPTS[$1]}"
|
||||
}
|
||||
|
||||
# check if the option value contains a string between commas
|
||||
option_value_contains() {
|
||||
local opt="${OPTS[$1]}"
|
||||
local str="$2"
|
||||
for i in ${(s:,:)opt}; do
|
||||
[[ "$i" == "$2" ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Messaging function with pretty coloring
|
||||
function _msg() {
|
||||
local msg="$2"
|
||||
@ -2004,7 +2018,7 @@ lock_tomb_with_key() {
|
||||
;;
|
||||
esac
|
||||
# TODO: check validity, only ext3 or 4 or btrfs support
|
||||
_message "Selected filesystem type $filesystem."
|
||||
_success "Selected filesystem type $filesystem."
|
||||
}
|
||||
|
||||
lo_mount $TOMBPATH
|
||||
@ -2273,6 +2287,9 @@ mount_tomb() {
|
||||
|
||||
_verbose "Tomb engraved as ::1 tomb name::" $TOMBNAME
|
||||
|
||||
if option_value_contains -o ro; then
|
||||
_message "Skipping filesystem checks in read-only"
|
||||
else
|
||||
_message "Checking filesystem via ::1::" $tombstat[3]
|
||||
case $filesystem in
|
||||
ext3|ext4)
|
||||
@ -2285,6 +2302,7 @@ mount_tomb() {
|
||||
_sudo btrfs filesystem label /dev/mapper/${TOMBMAPPER} ${TOMBNAME}
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# we need root from here on
|
||||
_sudo mkdir -p $tombmount
|
||||
@ -2328,6 +2346,7 @@ mount_tomb() {
|
||||
}
|
||||
|
||||
# write down the UID and TTY that opened the tomb
|
||||
option_value_contains -o ro || {
|
||||
_update_control_file ${tombmount}/.uid $_UID
|
||||
_update_control_file ${tombmount}/.tty $_TTY
|
||||
# also the hostname
|
||||
@ -2336,7 +2355,7 @@ mount_tomb() {
|
||||
# in minutes since 1970, this is printed at next open
|
||||
_update_control_file ${tombmount}/.last `date +%s`
|
||||
# human readable: date --date=@"`cat .last`" +%c
|
||||
|
||||
}
|
||||
# process bind-hooks (mount -o bind of directories)
|
||||
# and exec-hooks (execute on open)
|
||||
option_is_set -n || {
|
||||
@ -2345,10 +2364,14 @@ mount_tomb() {
|
||||
}
|
||||
|
||||
# Changes ownership to current user. This facilitates a lot
|
||||
# usability by single users. If a Tomb is "multiuser" and contains
|
||||
# ACL "by convention" using UNIX ownership that needs to be
|
||||
# preserved then this behavior can be deactivated using -p
|
||||
option_is_set -p || _sudo chown -R ${_UID}:${_GID} ${tombmount}
|
||||
# usability by single users. If a Tomb is opened read-only or it
|
||||
# is "multiuser" and contains ACL "by convention" using UNIX
|
||||
# ownership that needs to be preserved, then this behavior can be
|
||||
# deactivated using -p
|
||||
local dochown=true
|
||||
option_value_contains -o ro && dochown=false
|
||||
option_is_set -p && dochown=false
|
||||
$dochown && _sudo chown -R ${_UID}:${_GID} ${tombmount}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user