mbox

[1/7] util: add lock/unlock function

Message ID 1497900050-27692-1-git-send-email-jonatan.schlag@ipfire.org
State Superseded
Headers

Message

Jonatan Schlag June 20, 2017, 5:20 a.m. UTC
  This function easily lock or unlock a file.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/functions/functions.util | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

Michael Tremer June 21, 2017, 3:11 a.m. UTC | #1
Hi,

did you not like these?

http://git.ipfire.org/?p=network.git;a=blob;f=src/functions/functions.lock;h=fac86bddc336a6d1dd13d0e95f8c6ad683ccbaad;hb=HEAD

-Michael

On Mon, 2017-06-19 at 21:20 +0200, Jonatan Schlag wrote:
> This function easily lock or unlock a file.
> 
> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
> ---
>  src/functions/functions.util | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/src/functions/functions.util b/src/functions/functions.util
> index 4b6f956..23e5a4b 100644
> --- a/src/functions/functions.util
> +++ b/src/functions/functions.util
> @@ -738,3 +738,17 @@ hex2dec() {
>  dec2hex() {
>  	printf "%02x\n" "${1}"
>  }
> +
> +lock_file() {
> +	assert [ $# -eq 1 ]
> +	local file=${1}
> +
> +	touch "${file}.lock"
> +}
> +
> +unlock_file() {
> +	assert [ $# -eq 1 ]
> +	local file=${1}
> +
> +	rm -f "${file}.lock"
> +}