diff options
| author | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2026-03-02 20:55:12 +0300 |
|---|---|---|
| committer | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2026-03-02 20:55:12 +0300 |
| commit | 637f7ce651a45a217f31c9dbcc5878963a6f9d38 (patch) | |
| tree | 3fe2ae422acd0cc3490b42f1a08327f88d63ac15 /units | |
| parent | c438df5cfa64dcabbb3d173c30ded316b300a7b3 (diff) | |
*/*: Switch to single lock per single user directory
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
Diffstat (limited to 'units')
| -rw-r--r-- | units/export.zsh | 116 | ||||
| -rw-r--r-- | units/ib_lock.zsh | 4 | ||||
| -rw-r--r-- | units/ib_token.zsh | 4 |
3 files changed, 4 insertions, 120 deletions
diff --git a/units/export.zsh b/units/export.zsh deleted file mode 100644 index e92f612..0000000 --- a/units/export.zsh +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright (C) 2024-2026 Maria Lisina -# Copyright (C) 2024-2026 Danil Lisin -# SPDX-License-Identifier: Apache-2.0 - -if ! [[ -d "${user_config}" ]] -then - output_text="No user data found" - return -fi - -until mkdir "${cache}/${user_id}.lock" -do - sleep 1 -done - -rm -f "${cache}/${user_id}.tar" - -if ! tar c -hf "${cache}/${user_id}.tar" -C "${users}" "${user_id}" -then - output_text="Something went wrong, try again later" - - rmdir "${cache}/${user_id}.lock" - return -fi - -if ! output_data="$( - curl --connect-timeout ${connrefused_timeout} \ - --data-urlencode "chat_id=${chat_id}" \ - --data-urlencode "action=upload_document" \ - --get \ - --max-time ${internal_timeout} \ - --proxy "${internal_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((internal_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${api_address}/bot${api_token}/sendChatAction" -)" -then - log_text="sendChatAction (${update_id}): Failed to access Telegram Bot API" - source "${units}/log.zsh" -fi - -if [[ -z "${log_text}" ]] && ! jq -e '.' <<< "${output_data}" > /dev/null -then - log_text="sendChatAction (${update_id}): An unknown error occurred" - source "${units}/log.zsh" -fi - -if [[ -z "${log_text}" && "$(jq -r '.ok' <<< "${output_data}")" != "true" ]] -then - error_description="$(jq -r '.description' <<< "${output_data}")" - - if [[ "${error_description}" != "null" ]] - then - log_text="sendChatAction (${update_id}): ${error_description}" - else - log_text="sendChatAction (${update_id}): An unknown error occurred" - fi - - source "${units}/log.zsh" -fi - -if ! output_data="$( - curl --connect-timeout ${connrefused_timeout} \ - --form "chat_id=${chat_id}" \ - --form "document=@${cache}/${user_id}.tar" \ - --form "reply_parameters=${reply_parameters}" \ - --get \ - --max-time ${internal_timeout} \ - --proxy "${internal_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((internal_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${api_address}/bot${api_token}/sendDocument" -)" -then - output_text="Failed to send user data" - - log_text="sendDocument (${update_id}): Failed to access Telegram Bot API" - source "${units}/log.zsh" - - rmdir "${cache}/${user_id}.lock" - return -fi - -if ! jq -e '.' <<< "${output_data}" > /dev/null -then - output_text="An unknown error occurred" - - log_text="sendDocument (${update_id}): An unknown error occurred" - source "${units}/log.zsh" - - rmdir "${cache}/${user_id}.lock" - return -fi - -if [[ "$(jq -r '.ok' <<< "${output_data}")" != "true" ]] -then - output_text="Failed to send user data" - error_description="$(jq -r '.description' <<< "${output_data}")" - - if [[ "${error_description}" != "null" ]] - then - log_text="sendDocument (${update_id}): ${error_description}" - else - log_text="sendDocument (${update_id}): An unknown error occurred" - fi - - source "${units}/log.zsh" -fi - -rmdir "${cache}/${user_id}.lock" diff --git a/units/ib_lock.zsh b/units/ib_lock.zsh index 16bb2d3..b2c8c49 100644 --- a/units/ib_lock.zsh +++ b/units/ib_lock.zsh @@ -2,11 +2,11 @@ # Copyright (C) 2024-2026 Danil Lisin # SPDX-License-Identifier: Apache-2.0 -until mkdir "${user_config}_auth.lock" +until mkdir "${user_config}.lock" do sleep 1 done source "${units}/ib_auth.zsh" -rmdir "${user_config}_auth.lock" +rmdir "${user_config}.lock" diff --git a/units/ib_token.zsh b/units/ib_token.zsh index 617d91e..7ff05e1 100644 --- a/units/ib_token.zsh +++ b/units/ib_token.zsh @@ -2,7 +2,7 @@ # Copyright (C) 2024-2026 Danil Lisin # SPDX-License-Identifier: Apache-2.0 -until mkdir "${user_config}_auth.lock" +until mkdir "${user_config}.lock" do sleep 1 done @@ -38,4 +38,4 @@ then ib_headers="${ib_header} $(< "${token_file}")" fi -rmdir "${user_config}_auth.lock" +rmdir "${user_config}.lock" |
