fix: skip socket files in ipfs add to prevent errors#11149
fix: skip socket files in ipfs add to prevent errors#11149ljluestc wants to merge 2 commits intoipfs:masterfrom
Conversation
There was a problem hiding this comment.
Thanks for looking into this. The error handling approach here works, but it's a workaround at the client/rpc layer rather than fixing the issue at the source.
This means it does not fix cases where one performs import directly via ipfs add without running daemon (no RPC, direct repo access).
The "unrecognized file type" error originates in boxo's files/serialfile.go. A cleaner fix would be adding an option to SerialFileOptions to skip unsupported file types, similar to how DereferenceSymlinks works.
There's ongoing work for IPIP-499 that adds SerialFileOptions wiring through the stack:
- boxo#1088 - adds
SerialFileOptions.DereferenceSymlinks - go-ipfs-cmds#315 - wires
--dereference-symlinksflag to boxo - kubo#11148 - integrates the above
Once those PRs land, adding socket/device skipping becomes straightforward:
- Add
IgnoreUnsupported booltoSerialFileOptionsin boxo - Return
nil, nilinstead of error when the option is set - Update iterator to skip nil nodes
- Add
--ignore-unsupportedflag (name TBD, ideas welcome) in go-ipfs-cmds
This would fix the issue for all consumers (CLI, library, RPC) rather than just client/rpc, and avoids string-matching on error messages.
I'd suggest parking this PR until the IPIP-499 PRs merge, then we can add IgnoreUnsupported using the same pattern. Happy to help with that once the foundation is in place.
Fix: Gracefully Skip Socket Files in
ipfs addContext
When running
ipfs addon a directory that contains socket files, the operation fails with a misleading error:use of closed network connection. This breaks bulk add operations if a socket file is accidentally included (e.g., in a development directory) and prevents users from adding the rest of their files.Goal
The objective is to silently ignore unrecognized file types (specifically socket files) during the
ipfs addprocess. This ensures thatipfs addbehaves robustly, similar to how it handles other non-supported file types, and allows the operation to proceed for all valid files.Implementation Details
client/rpc/unixfs.go
We implemented a wrapper around the standard file directory iterator to catch and handle specific errors.
files.Directorythat acts as a factory for our custom iterator.DirIterator.client/rpc/unixfs_test.go
Added a new test file to verify this behavior isolation.
ipfs addcommand, ensuring the fix works in the real pipeline.Verification
Automated Tests
Run the new verification tests:
go test -v ./client/rpc -run TestSkippingIterator