Skip to content

Commit 8667976

Browse files
committed
fix: permissions of the region provider cache file
1 parent 132c9d2 commit 8667976

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

qiniu/http/regions_provider.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ def _lock_file_path(self):
300300
memo_cache={},
301301
persist_path=os.path.join(
302302
tempfile.gettempdir(),
303-
'qn-py-sdk-regions-cache.jsonl'
303+
'qn-py-sdk',
304+
'regions-cache.jsonl'
304305
),
305306
last_shrink_at=datetime.datetime.fromtimestamp(0),
306307
shrink_interval=datetime.timedelta(days=1),
@@ -520,8 +521,18 @@ def __init__(
520521
persist_path = kwargs.get('persist_path', None)
521522
last_shrink_at = datetime.datetime.fromtimestamp(0)
522523
if persist_path is None:
523-
persist_path = _global_cache_scope.persist_path
524-
last_shrink_at = _global_cache_scope.last_shrink_at
524+
cache_dir = os.path.dirname(_global_cache_scope.persist_path)
525+
try:
526+
# make sure the cache dir is available for all users.
527+
# we can not use the '/tmp' dir directly on linux,
528+
# because the permission is 0o1777
529+
os.makedirs(cache_dir, exist_ok=True)
530+
os.chmod(cache_dir, 0o777)
531+
persist_path = _global_cache_scope.persist_path
532+
last_shrink_at = _global_cache_scope.last_shrink_at
533+
except Exception as err:
534+
logging.warning(
535+
'failed to create cache dir %s. error: %s', cache_dir, err)
525536

526537
shrink_interval = kwargs.get('shrink_interval', None)
527538
if shrink_interval is None:

0 commit comments

Comments
 (0)