Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Let only the import skip what it cannot copy

Fei2411057c2bcf83f1
diff --git a/app/src/copy-tree.mjs b/app/src/copy-tree.mjs
index 6df32487..bad02c38 100644
--- a/app/src/copy-tree.mjs
+++ b/app/src/copy-tree.mjs
@@ -42,16 +42,17 @@ async function relink(source, path, roots, to) {
/**
* Copy the folder `from` into `into`, making its links again (fs.cp makes symbolic links, which
- * Windows refuses without special rights). An entry that cannot be read, such as a junction to
- * nothing, or a link that cannot be made again, is skipped and listed.
+ * Windows refuses without special rights). With `skip`, an entry that cannot be read, such as a
+ * junction to nothing, or a link that cannot be made again, is skipped and listed; otherwise it
+ * fails the copy.
* @param {string} from
* @param {string} into
- * @param {{ force?: boolean, leave?: (path: string) => boolean, as?: string, signal?: AbortSignal }} [options]
+ * @param {{ force?: boolean, skip?: boolean, leave?: (path: string) => boolean, as?: string, signal?: AbortSignal }} [options]
* force: false keeps what is there already; leave: relative paths not to copy; as: where the
* copy will end up, when `into` is a staging folder that takes that name later
* @returns {Promise<string[]>} the relative paths that were skipped
*/
-export async function copyTree(from, into, { force = true, leave = () => false, as = into, signal } = {}) {
+export async function copyTree(from, into, { force = true, skip = false, leave = () => false, as = into, signal } = {}) {
// The folder can itself be a link; its contents are what is copied.
const origin = real(from)
const links = []
@@ -64,7 +65,7 @@ export async function copyTree(from, into, { force = true, leave = () => false,
const path = relative(origin, source)
if (path !== '' && leave(path)) return false
if (path === '') return true
- const info = await lstat(source).catch(() => undefined)
+ const info = await lstat(source).catch((error) => { if (!skip) throw error })
if (info === undefined) skipped.push(path)
else if (info.isSymbolicLink()) links.push(path)
return info?.isSymbolicLink() === false
@@ -75,7 +76,10 @@ export async function copyTree(from, into, { force = true, leave = () => false,
signal?.throwIfAborted()
const at = join(into, path)
if (!force && await lstat(at).then(() => true, () => false)) continue
- await relink(join(origin, path), at, roots, resolve(as)).catch(() => { skipped.push(path) })
+ await relink(join(origin, path), at, roots, resolve(as)).catch((error) => {
+ if (!skip) throw error
+ skipped.push(path)
+ })
}
return skipped
}
diff --git a/app/src/import.mjs b/app/src/import.mjs
index b5e4451c..d7f276f0 100644
--- a/app/src/import.mjs
+++ b/app/src/import.mjs
@@ -184,7 +184,7 @@ export async function importTeam({ from, to, workspace, profile, dsh, signal })
await mkdir(workspace, { recursive: true })
if (existsSync(join(oldBot, 'workspace'))) {
// Bots that ran npm or pnpm there leave links, some of them to nothing.
- const skipped = await copyTree(join(oldBot, 'workspace'), workspace, { force: false, signal })
+ const skipped = await copyTree(join(oldBot, 'workspace'), workspace, { force: false, skip: true, signal })
if (skipped.length > 0) console.warn('DeepSeek Bot: the import skipped what it could not read in the old team workspace:', skipped)
}
signal?.throwIfAborted()
diff --git a/app/src/move-data.mjs b/app/src/move-data.mjs
index 40fa1b43..78979ae3 100644
--- a/app/src/move-data.mjs
+++ b/app/src/move-data.mjs
@@ -56,8 +56,8 @@ export async function copyData(from, to, signal) {
await mkdir(stage)
try {
await writeFile(join(stage, MARK), '')
- const skipped = await copyTree(from, stage, { as: to, leave: path => LEFT_BEHIND.some(pattern => pattern.test(path)), signal })
- if (skipped.length > 0) console.warn('DeepSeek Bot: the data move skipped what it could not read:', skipped)
+ // Anything left out would be missing from the data the app moves on to, so it stops the move.
+ await copyTree(from, stage, { as: to, leave: path => LEFT_BEHIND.some(pattern => pattern.test(path)), signal })
signal?.throwIfAborted()
if (existsSync(to)) await rmdir(to)
await rename(stage, to)
diff --git a/app/test/move-data.test.mjs b/app/test/move-data.test.mjs
index 38a88ac6..c77d097c 100644
--- a/app/test/move-data.test.mjs
+++ b/app/test/move-data.test.mjs
@@ -3,6 +3,7 @@ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, readlink
import { tmpdir } from 'node:os'
import { dirname, join, parse } from 'node:path'
import { test } from 'node:test'
+import { copyTree } from '../src/copy-tree.mjs'
import { copyData, installFolder, moveProblem } from '../src/move-data.mjs'
const write = (path, text) => {
@@ -148,3 +149,16 @@ test('links in the data lead inside the copy, not back into the old folder', asy
}
assert.equal(readFileSync(join(to, 'bot', 'absolute', 'g', 's1', 'log.jsonl'), 'utf8'), 'chat')
})
+
+// Windows makes a link to nothing that is not a folder only with special rights, which the
+// tests do not have, so there it is a link the copy cannot make again.
+test('a link the move cannot make again stops the move; the import skips it', { skip: process.platform !== 'win32' }, async (t) => {
+ const { root, from } = setup(t)
+ symlinkSync(join(root, 'gone'), join(from, 'lost'), 'junction')
+ const to = join(root, 'new')
+ await assert.rejects(copyData(from, to), { code: 'EPERM' })
+ assert.equal(existsSync(to), false)
+ assert.deepEqual(readdirSync(root).filter(name => name.includes('.moving-')), [])
+ assert.deepEqual(await copyTree(from, join(root, 'files'), { skip: true }), ['lost'])
+ assert.equal(readFileSync(join(root, 'files', 'sessions', 'g', 's1', 'log.jsonl'), 'utf8'), 'chat')
+})