Skip to content

fix(filesync): syncing a re-included file under a gitignored dir failed with no such file or directory - #13439

Merged
grouville merged 3 commits into
dagger:mainfrom
grouville:filesync-reincluded-parent
Jun 17, 2026
Merged

grouville merged 3 commits into
dagger:mainfrom
grouville:filesync-reincluded-parent

Conversation

@grouville

@grouville grouville commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

Problem

A .gitignore that ignores a directory but re-includes a file inside it broke filesync:

foo/
!foo/bar.txt

The receiver skips gitignored dirs, so it never created foo/ in the engine-side mirror. And then, failed to write the re-included file:

open <mirror>/foo/bar.txt: no such file or directory

Fix

Gitignored dirs are now remembered instead of dropped.

When a visible file inside one needs to be written, its missing parent dirs are created first, reusing the normal dir-creation path so the dirs get the client's metadata and concurrent syncs stay consistent:

path client mirror (engine copy) snapshot (pipeline input)
foo/ ignored created on demand, so bar.txt can be written present, but only as bar.txt's parent dir
foo/bar.txt re-included written synced ✓
foo/ignored.txt ignored never written absent ✓

Note

Current implementation keeps the dir itself out of the cache key: the pattern foo/ declares it ignored, and only bar.txt was re-included. I am unsure about that

Test

To run the regression test:

go test ./engine/filesync -run '^TestSyncReincludedFileUnderIgnoredParent$' -count=1

@grouville grouville changed the title fix(filesync): syncing a re-included file under a gitignored dir failed with "no such file or directory" fix(filesync): syncing a re-included file under a gitignored dir failed with no such file or directory Jun 12, 2026
@grouville
grouville marked this pull request as ready for review June 12, 2026 23:50
@grouville

grouville commented Jun 13, 2026 •

Copy link
Copy Markdown
Member Author

Note

After thinking about it, I htink i do need to include the generated folder into the cache key 🤔

@grouville
grouville force-pushed the filesync-reincluded-parent branch 5 times, most recently from 4201109 to 16ca978 Compare June 16, 2026 21:24
Comment thread engine/filesync/localfs.go Resolved
Comment thread engine/filesync/localfs.go Resolved
@grouville
grouville force-pushed the filesync-reincluded-parent branch from 16ca978 to f898b67 Compare June 17, 2026 00:05
With "foo/" ignored and "!foo/bar.txt" re-included, Sync skipped
creating foo/ in the mirror, then failed to write the visible file:

    open <mirror>/foo/bar.txt: no such file or directory

Now ignored dirs are recorded with their stat and created on demand
when a visible descendant needs them. Creation goes through the
existing local.Mkdir so the dirs get the client's metadata and stay in
the changeCache for dedup/conflict detection across concurrent syncs.

bar.txt is synced like any other visible file. `foo/` is not really
synced: it shows up in the snapshot only because the file needs a
parent dir (mkdir -p before cp), and it is never hashed into the cache
key. That part is intentional: a chmod on an ignored dir should not
rebuild anything, and git doesn't track dir metadata either. It does
mean an ignored dir's mode/owner can differ between a cache hit and a
fresh sync, but it seems to already be a corner case we're fine with ?

Regression test verified red/green against the old implementation.

Signed-off-by: Guillaume de Rouville <[email protected]>
When a directory is gitignored but a child file is re-included, filesync has
to create the ignored parent dir in the mirror before writing the visible
child. For example:

    foo/
    !foo/bar.txt

The final snapshot can then contain /foo/bar.txt, and therefore /foo. The
sync path created that parent, but did not record the synthetic directory in
the content-hash cache context. That made the committed ref inconsistent:
checksum data knew about /foo/bar.txt but not /foo, so Checksum("/foo")
returned "not found".

Record the applied mkdir for each ignored parent directory in cacheCtx, using
the same copyPath-relative HandleChange pattern as other sync changes. The
directory is not added to the `only` copy filter, so ignored content is still
not copied into the final snapshot.

Add a regression test for a full sync with foo/ ignored and !foo/bar.txt
re-included, and check that Checksum("/foo") succeeds. The test also stores
relPathFound in an atomic flag because the full sync path handles files in
parallel under the race detector.

Signed-off-by: Guillaume de Rouville <[email protected]>
The previous filesync cache metadata fix handled the cold Add/Modify paths:
when foo/ is ignored but !foo/bar.txt is re-included, sync creates foo/ in
the mirror and records that synthetic parent in cacheCtx.

A repeat sync through the same MirrorSharedState can take a different path.
Once the mirror is warm, foo/bar.txt can diff as ChangeKindNone, which went
straight to GetPreviousChange. That produced a new cacheCtx without recording
foo/, so the committed ref could again contain /foo while Checksum("/foo")
failed with "not found".

Call ensureIgnoredParentDirs before GetPreviousChange in the ChangeKindNone
arm so each full sync records the synthetic ignored parent whenever the
visible re-included child is still present. Add a fast path when no ignored
dirs were collected to avoid unnecessary parent walks.

Update the regression test to sync twice through one MirrorSharedState. The
first sync covers cold mirror creation; the second covers the warm
ChangeKindNone path. Both refs must allow Checksum("/foo").

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the filesync-reincluded-parent branch from f898b67 to 7c09fc8 Compare June 17, 2026 00:18
@grouville
grouville requested a review from sipsma June 17, 2026 00:42
@grouville
grouville merged commit 7d0d544 into dagger:main Jun 17, 2026
81 checks passed
marcosnils pushed a commit that referenced this pull request Jun 17, 2026
…ed with `no such file or directory` (#13439)

* fix: create gitignored parent dirs for re-included files in filesync

With "foo/" ignored and "!foo/bar.txt" re-included, Sync skipped
creating foo/ in the mirror, then failed to write the visible file:

    open <mirror>/foo/bar.txt: no such file or directory

Now ignored dirs are recorded with their stat and created on demand
when a visible descendant needs them. Creation goes through the
existing local.Mkdir so the dirs get the client's metadata and stay in
the changeCache for dedup/conflict detection across concurrent syncs.

bar.txt is synced like any other visible file. `foo/` is not really
synced: it shows up in the snapshot only because the file needs a
parent dir (mkdir -p before cp), and it is never hashed into the cache
key. That part is intentional: a chmod on an ignored dir should not
rebuild anything, and git doesn't track dir metadata either. It does
mean an ignored dir's mode/owner can differ between a cache hit and a
fresh sync, but it seems to already be a corner case we're fine with ?

Regression test verified red/green against the old implementation.

Signed-off-by: Guillaume de Rouville <[email protected]>

* fix: record re-included filesync parent dirs in cache metadata

When a directory is gitignored but a child file is re-included, filesync has
to create the ignored parent dir in the mirror before writing the visible
child. For example:

    foo/
    !foo/bar.txt

The final snapshot can then contain /foo/bar.txt, and therefore /foo. The
sync path created that parent, but did not record the synthetic directory in
the content-hash cache context. That made the committed ref inconsistent:
checksum data knew about /foo/bar.txt but not /foo, so Checksum("/foo")
returned "not found".

Record the applied mkdir for each ignored parent directory in cacheCtx, using
the same copyPath-relative HandleChange pattern as other sync changes. The
directory is not added to the `only` copy filter, so ignored content is still
not copied into the final snapshot.

Add a regression test for a full sync with foo/ ignored and !foo/bar.txt
re-included, and check that Checksum("/foo") succeeds. The test also stores
relPathFound in an atomic flag because the full sync path handles files in
parallel under the race detector.

Signed-off-by: Guillaume de Rouville <[email protected]>

* fix: record re-included parent dirs on warm filesyncs

The previous filesync cache metadata fix handled the cold Add/Modify paths:
when foo/ is ignored but !foo/bar.txt is re-included, sync creates foo/ in
the mirror and records that synthetic parent in cacheCtx.

A repeat sync through the same MirrorSharedState can take a different path.
Once the mirror is warm, foo/bar.txt can diff as ChangeKindNone, which went
straight to GetPreviousChange. That produced a new cacheCtx without recording
foo/, so the committed ref could again contain /foo while Checksum("/foo")
failed with "not found".

Call ensureIgnoredParentDirs before GetPreviousChange in the ChangeKindNone
arm so each full sync records the synthetic ignored parent whenever the
visible re-included child is still present. Add a fast path when no ignored
dirs were collected to avoid unnecessary parent walks.

Update the regression test to sync twice through one MirrorSharedState. The
first sync covers cold mirror creation; the second covers the warm
ChangeKindNone path. Both refs must allow Checksum("/foo").

Signed-off-by: Guillaume de Rouville <[email protected]>

---------

Signed-off-by: Guillaume de Rouville <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.7

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.7 - 2026-06-17

### Changed

- Bump default CNI IP address pool size to reduce address exhaustion under high container concurrency. by @sipsma in dagger/dagger#13394
- Bump Dang to v2.1.1, moving JSON encoding behind the `JSON` namespace (with a deprecated top-level `toJSON`) and picking up constructor scope and nullable input fixes. by @vito in dagger/dagger#13482

### Fixed

- `.env` file handling so non-matching variables are kept as hidden expansion context instead of being dropped, allowing later variables to expand against them. by @marcosnils in dagger/dagger#13490
- Filesync so syncing a re-included file under a gitignored directory (e.g. `foo/` ignored with `!foo/bar.txt`) no longer fails with `no such file or directory`; ignored parent dirs are now created on demand for visible descendants. by @grouville in dagger/dagger#13439
- A concurrent map panic during GC by guarding session client map iteration, preventing fatal `concurrent map iteration and map write` crashes. by @sipsma in dagger/dagger#13474
- Go SDK codegen so SDK auth config is forwarded to typedef generation, allowing modules with private transitive Go dependencies to resolve during codegen. by @grouville in dagger/dagger#13457
- Core enum handling to preserve conventional enum member names. by @shykes in dagger/dagger#13435
- The Apple `container` driver to honor the privileged option by granting all capabilities (`--cap-add ALL`), so the engine can bind-mount `/etc/resolv.conf` on startup with `container` 1.0.0's reduced default capability set. by @eunomie in dagger/dagger#13460
- Dang directive argument resolution so `@cache` (and other directive) arguments resolve against the declaring type's file scope, fixing `FunctionCachePolicy not found in env` errors in multi-file modules. by @vito in dagger/dagger#13455
- The report-mode heartbeat so it waits for its goroutine to exit before final render, avoiding interleaved output. by @kpenfound in dagger/dagger#13425
- Nullable result unwrapping for SDK input so nullable values are passed correctly into SDK functions. by @shykes in dagger/dagger#13401

### What to do next?

- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.7">https://github.com/dagger/dagger/releases/tag/v0.21.7</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!11763
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants