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

Submitted by Jonatan Schlag on June 19, 2017, 7:20 p.m.

Details

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

Commit Message

Jonatan Schlag June 19, 2017, 7:20 p.m.
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(+)

Patch hide | download patch | download mbox

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"
+}

Comments

Michael Tremer June 20, 2017, 5:11 p.m.
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"
> +}