dsh-crossterm 0.3.39 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bus.js +1 -1
- package/lib/cloud/session-backup.js +15 -4
- package/package.json +1 -1
package/lib/bus.js
CHANGED
|
@@ -145,15 +145,26 @@ export async function backupAttachments({ pan, layout, objectsRoot, stateFile, l
|
|
|
145
145
|
const remoteDir = layout.paths.attachmentDir
|
|
146
146
|
const result = { ok: true, total: 0, uploaded: 0, skipped: 0, bytes: 0, pending: 0, error: '' }
|
|
147
147
|
let files = []
|
|
148
|
-
|
|
148
|
+
// DSH 的附件仓库是两层结构:objects/<前两位>/<sha256>,只读顶层会一个都拿不到。
|
|
149
|
+
try {
|
|
150
|
+
for (const bucket of fs.readdirSync(objectsRoot, { withFileTypes: true })) {
|
|
151
|
+
if (bucket.isFile()) { files.push({ name: bucket.name, dir: objectsRoot }); continue }
|
|
152
|
+
if (!bucket.isDirectory()) continue
|
|
153
|
+
const sub = path.join(objectsRoot, bucket.name)
|
|
154
|
+
let inner = []
|
|
155
|
+
try { inner = fs.readdirSync(sub, { withFileTypes: true }) } catch { continue }
|
|
156
|
+
for (const f of inner) if (f.isFile()) files.push({ name: f.name, dir: sub })
|
|
157
|
+
}
|
|
158
|
+
} catch { return result }
|
|
149
159
|
result.total = files.length
|
|
150
|
-
const todo = files.filter((f) => !state.attachments[f])
|
|
160
|
+
const todo = files.filter((f) => !state.attachments[f.name])
|
|
151
161
|
result.skipped = files.length - todo.length
|
|
152
162
|
result.pending = Math.max(0, todo.length - maxFiles)
|
|
153
163
|
if (!todo.length) return result
|
|
154
164
|
await pan.mkdir(remoteDir)
|
|
155
|
-
for (const
|
|
156
|
-
const
|
|
165
|
+
for (const item of todo.slice(0, maxFiles)) {
|
|
166
|
+
const name = item.name
|
|
167
|
+
const full = path.join(item.dir, name)
|
|
157
168
|
try {
|
|
158
169
|
const st = fs.statSync(full)
|
|
159
170
|
await pan.put(full, `${remoteDir}/${name}`)
|