Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/lib/scheduled-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ describe("scheduled import path handling", () => {
)
})

it("preserves nested relative paths when the import root differs only in case (Windows)", () => {
const dest = scheduledImportDestinationForFile(
"C:/Users/Me/Wiki",
"C:/Users/Me/Inbox",
{
name: "report.pdf",
path: "c:/users/me/inbox/sub/report.pdf",
},
)

expect(dest).toBe(
"C:/Users/Me/Wiki/raw/sources/scheduled-import/sub/report.pdf",
)
})

it("does not copy files that are already under raw/sources", () => {
const dest = scheduledImportDestinationForFile(
projectPath,
Expand Down
11 changes: 9 additions & 2 deletions src/lib/scheduled-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ function dbFilePath(projectPath: string): string {
}

function dbDirectoryKey(importPath: string): string {
const normalized = normalizePath(importPath)
return caseFoldPath(normalizePath(importPath))
}

// Windows drive-letter and UNC paths are case-insensitive; fold them for
// comparison purposes only (never for the paths actually written to disk).
function caseFoldPath(normalized: string): string {
return /^[A-Za-z]:\//.test(normalized) || normalized.startsWith("//")
? normalized.toLowerCase()
: normalized
Expand Down Expand Up @@ -256,8 +261,10 @@ export function scheduledImportDestinationForFile(
}

const importRoot = normalizePath(importPath).replace(/\/+$/, "")
const sourceKey = caseFoldPath(source)
const importRootKey = caseFoldPath(importRoot)
const relative =
source === importRoot || !source.startsWith(`${importRoot}/`)
sourceKey === importRootKey || !sourceKey.startsWith(`${importRootKey}/`)
? file.name
: source.slice(importRoot.length + 1)

Expand Down
Loading