{"thread":{"id":"66513","subject":"fsmonitor (Linux): edits in subdirectories of a renamed directory are missed","startedAt":"2026-10-13T13:39:28Z","lastAt":"2026-10-13T13:39:28Z","messageCount":1,"participants":["Erik Cervin-Edin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"554857","messageId":"as4z1SskiPyrSKIa@vader","threadId":"66513","inReplyTo":null,"subject":"fsmonitor (Linux): edits in subdirectories of a renamed directory are missed","fromName":"Erik Cervin-Edin","fromEmail":"erik@cervined.in","sentAt":"2026-10-13T13:39:28Z","receivedAt":"2026-10-13T13:39:28Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\n\nWith the built-in fsmonitor daemon on Linux, I renamed a directory that\nhas a subdirectory, then edited a file in each:\n\n    git init repro && cd repro\n    git config core.fsmonitor true\n    mkdir -p old/pkg/sub new\n    echo a >old/pkg/top.txt\n    echo a >old/pkg/sub/f.txt\n    git add . && git commit -qm init\n    git status --short          # starts the daemon\n    git mv old/pkg new/pkg\n    git commit -qm move\n    echo b >>new/pkg/top.txt\n    echo b >>new/pkg/sub/f.txt\n    GIT_TRACE_FSMONITOR=1 git status --short\n\nWhat did you expect to happen? (Expected behavior)\n\nBoth edited files listed as modified:\n\n     M new/pkg/sub/f.txt\n     M new/pkg/top.txt\n\nWhat happened instead? (Actual behavior)\n\nOnly the file directly in the renamed directory is listed. The daemon\nreports the edit in the subdirectory under its path from before the\nrename:\n\n    fsmonitor_refresh_callback 'new/pkg/top.txt' (pos 1)\n    fsmonitor_refresh_callback INV: 'new/pkg/top.txt'\n    fsmonitor_refresh_callback CNT: 1\n    fsmonitor_refresh_callback 'old/pkg/sub/f.txt' (pos -3)\n     M new/pkg/top.txt\n\n`git -c core.fsmonitor=false status --short` lists both files.\n\nWhat's different between what you expected and what actually happened?\n\nChanges anywhere below a subdirectory of a renamed directory are\nmissing from status and diff, with no warning. It is not a\nrace: later edits in that subdirectory, made well after the rename, are\nmissed too. It persists until something invalidates the fsmonitor\nstate. I hit it moving a source package: 19 of 56 edited files were\nmissing from `git status`, all in subdirectories of the moved\ndirectory, and a commit made from that status would have left them\nout.\n\nAnything else you want to add:\n\nI believe the cause is in add_watch() in\ncompat/fsmonitor/fsm-listen-linux.c. An inotify watch follows the\ndirectory's inode, so the subdirectories of a renamed directory are\nstill watched. When the rename is processed, they are registered again\nunder their new paths with IN_MASK_CREATE, inotify_add_watch() fails\nwith EEXIST, and add_watch() returns early without updating the\ndescriptor-to-path map. Only the renamed directory's own entry gets its\nnew path.\n\nPatrick Steinhardt asked about exactly this in review of v5 of the\nLinux listener:\n\n  https://lore.kernel.org/git/aZ1bRQv9Cjke298f@pks.im/\n\n  > In case the watch already exists, can't it be the case that we\n  > have raced e.g. during a rename? [...] If we then see EEXIST we\n  > wouldn't update the hash map and thus keep the old path intact.\n\nAs far as I can see that question was not answered on the list, and\nv15 of the series still returns early on EEXIST. It turns out to be\ndeterministic rather than a race.\n\n\n[System Info]\ngit version:\ngit version 2.56.0.rc2.275.gfcaf1f5383\ncpu: x86_64\nbuilt from commit: fcaf1f5383f52c5ebd5e2df3ea023601e2084b10\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nrust: enabled\nfeature: fsmonitor--daemon\ngettext: enabled\nlibcurl: 8.18.0\nOpenSSL: OpenSSL 3.5.8 25 Aug 2026\nzlib-ng: 2.3.3\nSHA-1: SHA1_DC\nSHA-256: SHA256_BLK\ndefault-ref-storage-format: files\ndefault-hash: sha1\nuname: Linux 7.2.9-200.fc44.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Oct  3 19:59:55 UTC 2026 x86_64\ncompiler info: gnuc: 16.2\nlibc info: glibc: 2.43\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n\n"}]}