Skip to content

Commit

Permalink
Fix: Make progress file path respect --config-dir parameter (#717)
Browse files Browse the repository at this point in the history
## 问题
进度文件路径被硬编码为使用 `const.ProgressPath`,而没有遵循用户通过 `--config-dir` 参数指定的配置目录。相比之下,其他配置文件(token, settings等)都正确使用了指定目录。

## 修改内容
- 在 `__init__` 方法中添加了 `self._progresspath` 的初始化
- 更新所有进度文件操作,使用 `self._progresspath` 替代 `const.ProgressPath`
- 使用 `configdir + os.sep + filename` 的方式统一配置文件的路径拼接风格

## 受影响的方法
- `_update_progress_entry()`
- `_delete_progress_entry()`
- `_upload_file_slices()`

之前并发提交时遇到大文件会因为进度文件冲突报错,修改后设置各自的config-dir就不会报错了。
  • Loading branch information
Bluetea577 authored Jan 30, 2025
1 parent 9e15307 commit fa2e87f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions bypy/bypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def __init__(self,
self._configdir = configdir.rstrip("/\\ ")
makedir(self._configdir)
# os.path.join() may not handle unicode well on Python 2.7
self._progresspath = configdir + os.sep + const.ProgressFileName
self._tokenpath = configdir + os.sep + const.TokenFileName
self._settingpath = configdir + os.sep + const.SettingFileName
self._setting = {}
Expand Down Expand Up @@ -1562,26 +1563,26 @@ def _update_progress_entry(self, fullpath):
progress = {}

try:
progress = jsonload(const.ProgressPath)
progress = jsonload(self._progresspath)
except Exception as ex:
perr("Error loading the progress for: '{}'.\n{}.".format(fullpath, formatex(ex)))

self.pd("Updating slice upload progress for {}".format(fullpath))
progress[fullpath] = (self._slice_size, self._slice_md5s)

try:
jsondump(progress, const.ProgressPath, mpsemaphore)
jsondump(progress, self._progresspath, mpsemaphore)
except Exception as ex:
perr("Error updating the progress for: '{}'.\n{}.".format(fullpath, formatex(ex)))

def _delete_progress_entry(self, fullpath):
try:
progress = jsonload(const.ProgressPath)
progress = jsonload(self._progresspath)
# http://stackoverflow.com/questions/11277432/how-to-remove-a-key-from-a-python-dictionary
#del progress[fullpath]
self.pd("Removing slice upload progress for {}".format(fullpath))
progress.pop(fullpath, None)
jsondump(progress, const.ProgressPath, mpsemaphore)
jsondump(progress, self._progresspath, mpsemaphore)
except Exception as ex:
perr("Error deleting the progress for: '{}'.\n{}.".format(fullpath, formatex(ex)))

Expand All @@ -1607,14 +1608,14 @@ def _upload_file_slices(self, localpath, remotepath, ondup = 'overwrite'):
progress = {}
initial_offset = 0
# create an empty progress file first
if not os.path.exists(const.ProgressPath):
if not os.path.exists(self._progresspath):
try:
jsondump(progress, const.ProgressPath, mpsemaphore)
jsondump(progress, self._progresspath, mpsemaphore)
except Exception as ex:
perr("Error savingprogress, no resumption.\n{}".format(formatex(ex)))

try:
progress = jsonload(const.ProgressPath)
progress = jsonload(self._progresspath)
except Exception as ex:
perr("Error loading progress, no resumption.\n{}".format(formatex(ex)))

Expand Down

0 comments on commit fa2e87f

Please sign in to comment.