Skip to content

Commit 188d459

Browse files
andersktimabbott
authored andcommitted
ruff: Fix S108 Probable insecure usage of temporary file or directory.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 8ebacd0 commit 188d459

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
platformdirs

zulip/integrations/codebase/zulip_codebase_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import os
12
from typing import Optional
23

4+
import platformdirs
5+
36
# Change these values to configure authentication for your codebase account
47
# Note that this is the Codebase API Username, found in the Settings page
58
# for your account
@@ -36,4 +39,4 @@
3639

3740
# This file is used to resume this mirror in case the script shuts down.
3841
# It is required and needs to be writeable.
39-
RESUME_FILE = "/var/tmp/zulip_codebase.state"
42+
RESUME_FILE = os.path.join(platformdirs.user_state_dir(), "zulip_codebase.state")

zulip/integrations/log2zulip/log2zulip

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import platform
99
import re
1010
import subprocess
1111
import sys
12-
import tempfile
1312
import traceback
1413
from pathlib import Path
1514
from typing import List
@@ -26,9 +25,11 @@ except ImportError:
2625

2726
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../"))
2827

28+
import platformdirs
29+
2930
import zulip
3031

31-
temp_dir = "/var/tmp/" if os.name == "posix" else tempfile.gettempdir()
32+
state_dir = platformdirs.user_state_dir()
3233

3334

3435
def mkdir_p(path: str) -> None:
@@ -71,7 +72,7 @@ def process_lines(raw_lines: List[str], file_name: str) -> None:
7172

7273

7374
def process_logs() -> None:
74-
data_file_path = os.path.join(temp_dir, "log2zulip.state")
75+
data_file_path = os.path.join(state_dir, "log2zulip.state")
7576
mkdir_p(os.path.dirname(data_file_path))
7677
if not os.path.exists(data_file_path):
7778
Path(data_file_path).write_text("{}")
@@ -106,7 +107,7 @@ if __name__ == "__main__":
106107
parser.add_argument("--control-path", default="/etc/log2zulip.conf")
107108
args = parser.parse_args()
108109

109-
lock_path = os.path.join(temp_dir, "log2zulip.lock")
110+
lock_path = os.path.join(state_dir, "log2zulip.lock")
110111
if os.path.exists(lock_path):
111112
# This locking code is here to protect against log2zulip,
112113
# running in a cron job, ending up with multiple copies
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
platformdirs

zulip/integrations/zephyr/zephyr_mirror_backend.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,10 @@ def die_gracefully(signal: int, frame: Optional[FrameType]) -> None:
12851285
logger.error("\nnagios_path is required with nagios_class\n")
12861286
sys.exit(1)
12871287

1288+
if options.use_sessions and options.session_path is None:
1289+
logger.error("--session-path is required with --use-sessions")
1290+
sys.exit(1)
1291+
12881292
zulip_account_email = options.user + "@mit.edu"
12891293

12901294
start_time = time.time()
@@ -1330,9 +1334,6 @@ def die_gracefully(signal: int, frame: Optional[FrameType]) -> None:
13301334
if options.forward_mail_zephyrs is None:
13311335
options.forward_mail_zephyrs = subscribed_to_mail_messages()
13321336

1333-
if options.session_path is None:
1334-
options.session_path = f"/var/tmp/{options.user}"
1335-
13361337
if options.forward_from_zulip:
13371338
child_pid: Optional[int] = os.fork()
13381339
if child_pid == 0:

0 commit comments

Comments
 (0)