Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filenignore behavior for directories #57

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
5 changes: 3 additions & 2 deletions src/lib/deltas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export class Deltas {
.sort((a, b) => a.path.split("/").length - b.path.split("/").length)
// Filter by ignored paths
.filter(delta => {
const trailingSlash = delta.type.endsWith("Directory") ? "/" : ""
if (
delta.type === "renameLocalDirectory" ||
delta.type === "renameLocalFile" ||
Expand All @@ -504,15 +505,15 @@ export class Deltas {
return false
}

if (this.sync.ignorer.ignores(delta.from) || this.sync.ignorer.ignores(delta.to)) {
if (this.sync.ignorer.ignores(delta.from + trailingSlash) || this.sync.ignorer.ignores(delta.to + trailingSlash)) {
return false
}
} else {
if (this.sync.excludeDotFiles && pathIncludesDotFile(delta.path)) {
return false
}

if (this.sync.ignorer.ignores(delta.path)) {
if (this.sync.ignorer.ignores(delta.path + trailingSlash)) {
return false
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/lib/filesystems/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export class LocalFileSystem {

public isPathIgnored(
relativePath: string,
absolutePath: string
absolutePath: string,
type: "file" | "directory"
): { ignored: true; reason: LocalTreeIgnoredReason } | { ignored: false } {
if (this.ignoredCache.get(relativePath)) {
return this.ignoredCache.get(relativePath)!
Expand Down Expand Up @@ -186,7 +187,8 @@ export class LocalFileSystem {
}
}

if (this.sync.ignorer.ignores(relativePath)) {
const trailingSlash = type === "directory" ? "/" : ""
if (this.sync.ignorer.ignores(relativePath + trailingSlash)) {
this.ignoredCache.set(relativePath, {
ignored: true,
reason: "filenIgnore"
Expand Down Expand Up @@ -316,27 +318,27 @@ export class LocalFileSystem {

pathsAdded[lowercasePath] = true

const ignored = this.isPathIgnored(entryItem, absolutePath)
let stats: fs.Stats | null = null

if (ignored.ignored) {
try {
stats = await fs.stat(absolutePath)
} catch {
this.getDirectoryTreeCache.ignored.push({
localPath: absolutePath,
relativePath: entryPath,
reason: ignored.reason
reason: "permissions"
})

continue
}

let stats: fs.Stats | null = null
const ignored = this.isPathIgnored(entryItem, absolutePath, stats.isFile() ? "file" : "directory")

try {
stats = await fs.stat(absolutePath)
} catch {
if (ignored.ignored) {
this.getDirectoryTreeCache.ignored.push({
localPath: absolutePath,
relativePath: entryPath,
reason: "permissions"
reason: ignored.reason
})

continue
Expand Down
3 changes: 2 additions & 1 deletion src/lib/filesystems/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ export class RemoteFileSystem {
}
}

if (this.sync.ignorer.ignores(relativePath)) {
const trailingSlash = type === "directory" ? "/" : ""
if (this.sync.ignorer.ignores(relativePath + trailingSlash)) {
this.ignoredCache.set(key, {
ignored: true,
reason: "filenIgnore"
Expand Down
Loading