commit 6ff616c882c6762bb32b366495ed698406e0c3a3
parent e3c34f9020ba5ba2da783ce56849a1ccd0a11e8d
Author: Jaromil <jaromil@dyne.org>
Date: Thu, 22 Oct 2015 09:54:42 +0200
locking code cleanup and fix installation perms
Diffstat:
3 files changed, 81 insertions(+), 57 deletions(-)
diff --git a/build/install-gnu.sh b/build/install-gnu.sh
@@ -43,6 +43,8 @@ for l in `ls $JARO_LIBEXEC/zlibs/ | grep -v '.zwc$'`; do
zcompile $JARO_LIBEXEC/zlibs/$l
done
+chmod -R a+rX "$JARO_SHARE"
+
mkdir -p $PREFIX/bin
cat <<EOF > $PREFIX/bin/jaro
#!/usr/bin/env zsh
diff --git a/src/zlibs/locking b/src/zlibs/locking
@@ -4,7 +4,7 @@
#
# a tool to easily and privately handle your e-mail communication
#
-# Copyleft (C) 2010-2014 Denis Roio <jaromil@dyne.org>
+# Copyleft (C) 2010-2015 Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
@@ -22,21 +22,32 @@
lock() {
- func "$dotlock: $1"
- ${WORKDIR}/bin/dotlock "$1"
+ fn "lock $@"
+ _file=$1
+ req=(_file)
+ freq=($_file)
+ ckreq || return 1
+
+ if helper.isfound dotlock; then
+ dotlock=`command -v dotlock`
+ else
+ dotlock="${WORKDIR}/bin/dotlock"
+ fi
+
+ ${dotlock} "$_file"
res=$?
case $res in
- 1) error "Cannot lock non existing file: $1"
+ 1) error "Cannot lock non existing file: $_file"
return 1 ;;
- 3) error "Locked file in use: $1"
+ 3) error "Locked file in use: $_file"
pidcheck "$1"
return 3 ;;
- 5) error "Lock is impossible on: $1"
+ 5) error "Lock is impossible on: $_file"
return 5 ;;
# success
- 0) print "$$" > "$1.pid"
+ 0) print "$$" > "$_file.pid"
return 0 ;;
*) error "Unknown error locking: $res"
@@ -45,67 +56,85 @@ lock() {
}
newlock() { # lock file, create if not existing
- func "creating locked file: $1"
- touch "$1"
- chmod 600 "$1"
- lock "$1"
+ fn "newlock $@"
+ _file="$1"
+ req=(_file)
+ ckreq || return 1
+
+ touch "$_file"
+ chmod 600 "$_file"
+ lock "$_file"
}
pidcheck() { # check if lock belongs to us
- if [ -r "${1}.pid" ]; then
+ fn "pidcheck $@"
+ _pid="$1"
+ req=(_pid)
+ ckreq || return 1
+
+ if [ -r "${_pid}.pid" ]; then
- lockpid="`cat ${1}.pid`"
- func "pidcheck: $lockpid"
- if [[ "$$" = "$lockpid" ]]; then
- func "${1} lock belongs to us"
- else
+ lockpid="`cat ${_pid}.pid`"
+ func "pidcheck: $lockpid"
+ if [[ "$$" = "$lockpid" ]]; then
+ func "${_pid} lock belongs to us"
+ else
- error "Unlock attempt by multiple processes on `basename $1`"
- [[ "$FORCE" = "1" ]] || { _prun=1
- while [ "$_prun" = "1" ]; do
+ error "Unlock attempt by multiple processes on `basename $_pid`"
+ [[ "$FORCE" = "1" ]] || {
+ _prun=1
+ while [ "$_prun" = "1" ]; do
[[ $global_quit = 1 ]] && { break }
- for p in `ps ax | awk '{ print $1 }'`; do
- { test "$p" = "$lockpid" } && { break }
- done
- if [ "$p" = "$lockpid" ]; then
- act "Owner (${lockpid}) still running, waiting release..."
- sleep 1;
+ for p in `ps ax | awk '{ print $_pid }'`; do
+ { test "$p" = "$lockpid" } && { break }
+ done
+ if [ "$p" = "$lockpid" ]; then
+ act "Owner (${lockpid}) still running, waiting release..."
+ sleep 1;
continue
- else
- act "Owner (${lockpid}) not running, taking over the lock"
- rm -f "${1}.pid"; print "$$" > "${1}.pid"
- _prun=0
- fi
- done
- }
- act "left behind by $lockpid - we ($$) will take over"
+ else
+ act "Owner (${lockpid}) not running, taking over the lock"
+ rm -f "${_pid}.pid"; print "$$" > "${_pid}.pid"
+ _prun=0
+ fi
+ done
+ }
+ act "left behind by $lockpid - we ($$) will take over"
- fi
+ fi
else # pid file doesn't exists
- func "no pid file found for: $1"
- func "we will take it over"
- print "$$" > "${1}.pid"
+ func "no pid file found for: $_pid"
+ func "we will take it over"
+ print "$$" > "${_pid}.pid"
fi
return 0
}
unlock() {
- func "unlock: $1"
+ fn "unlock $@"
+ _file="$1"
+ req=(_file)
+ ckreq || return 1
- pidcheck "$1"
+ pidcheck "$_file"
[[ $? = 0 ]] || { return 1 }
- ${WORKDIR}/bin/dotlock -u "$1"
+ ${WORKDIR}/bin/dotlock -u "$_file"
[[ $? = 0 ]] || {
- rm -f "$1.lock"
- [[ $? = 0 ]] || { error "Unable to unlock: $1"; return 1 }
+ rm -f "${_file}.lock"
+ [[ $? = 0 ]] || { error "Unable to unlock: $_file"; return 1 }
}
- [[ -r "${1}.pid" ]] && { rm -f "${1}.pid" }
+ [[ -r "${_file}.pid" ]] && { rm -f "${_file}.pid" }
return 0
}
+
unlink() { # delete a file that we are locking
- unlock "$1"
- ${=rm} "$1"
- func "$1 removed"
+ fn "unlink $@"
+ _file="$1"
+ ckreq || return 1
+
+ unlock "$_file"
+ ${=rm} "$_file"
+ func "$_file removed"
}
diff --git a/src/zlibs/parse b/src/zlibs/parse
@@ -38,17 +38,13 @@ extract_mails() {
# learn from senders, recipients or all
_action="$1"
-
- # # -U eliminates duplicates
- # typeset -aU _res
-
_found=0
for m in ${(f)_mails}; do
# e_parse fills in e_addr(map) and e_parsed(newline term str)
hdr $m | e_parse $_action
for _e in ${(k)e_addr}; do
- # _res+=("${(v)e_addr[$_e]} <$_e>")
+
print - "${(v)e_addr[$_e]} <$_e>"
_found=$(( $_found + 1 ))
done
@@ -62,11 +58,8 @@ extract_mails() {
}
}
done
- # print out results
- # for r in $_res; do
- # print - $r
- # done
- notice "${_found} unique addresses extracted"
+
+ notice "${_found} addresses extracted (including duplicates)"
}
# extract all addresses found into a maildir