Repository navigation
Add a Files service for folders you choose in Settings, with writes off by default - #385
Conversation
|
Following up from #364: |
|
@mattt Rebased onto the updated #377 and fixed both items: |
20df210 to
6ee7bb1
Compare
|
Thanks, @oliverames. Both fixes are in. Three more things before I merge:
I'd still like to see add, relaunch, read, write, and trash run in a signed, sandboxed build. This also needs a rebase onto |
Mattt's mattt#385 review: - files_stat no longer unwraps canonicalComponents.last! for a link that resolves to the shared root: an empty canonical path is the root. - files_trash does not report success when F_GETPATH fails; it reports that the result could not be confirmed. If putting a swapped item back fails, the error is reported instead of dropped. - write closes its output descriptor when writeAll throws, on both the replace and the create path. A test covers stat on a link to the shared root.
6ee7bb1 to
803d2a3
Compare
Mattt's mattt#385 review: - files_stat no longer unwraps canonicalComponents.last! for a link that resolves to the shared root: an empty canonical path is the root. - files_trash does not report success when F_GETPATH fails; it reports that the result could not be confirmed. If putting a swapped item back fails, the error is reported instead of dropped. - write closes its output descriptor when writeAll throws, on both the replace and the create path. A test covers stat on a link to the shared root.
|
Thanks @mattt. All three are fixed, and I ran the signed sandboxed pass you asked for.
The signed sandboxed pass ran on a Debug build: I added a folder in Settings → Files → Add Folder, quit and relaunched the app (both shared folders stayed available, so the bookmarks persist), then listed, read (byte for byte), wrote, and trashed a file. The file went to the Trash and was still there, so nothing was deleted. Originals untouched.
|
|
@mattt I went back over this and found one real hole and two smaller things, all fixed. The Photos library check could be skipped with a long s.
|
Mattt's mattt#385 review: - files_stat no longer unwraps canonicalComponents.last! for a link that resolves to the shared root: an empty canonical path is the root. - files_trash does not report success when F_GETPATH fails; it reports that the result could not be confirmed. If putting a swapped item back fails, the error is reported instead of dropped. - write closes its output descriptor when writeAll throws, on both the replace and the create path. A test covers stat on a link to the shared root.
f234ac1 to
7d72404
Compare
Tools list, read, stat, and search the folders a person shares, and write, append, make folders, move, and trash in them. Paths resolve inside a shared folder only, folders are opened one step at a time without following links, Photos libraries are refused, and nothing is deleted for good.
Settings lists the shared folders with Add and Remove. The service uses the Allow writes setting, which is off by default, so the tools that change files aren't listed until it is turned on. Folders are kept as app-scoped security-scoped bookmarks that iMCP opens only while a tool runs.
…very in FilesTests
Mattt's mattt#385 review: - files_stat no longer unwraps canonicalComponents.last! for a link that resolves to the shared root: an empty canonical path is the root. - files_trash does not report success when F_GETPATH fails; it reports that the result could not be confirmed. If putting a swapped item back fails, the error is reported instead of dropped. - write closes its output descriptor when writeAll throws, on both the replace and the create path. A test covers stat on a link to the shared root.
…name when files_write replaces a file APFS folds the long s, so a Photos library could be named with a spelling that passed the name check, and files_trash and files_move never open their final component. Both now check where the item is on disk, and the name check folds case, diacritics and width. files_write copies the replaced file's extended attributes, ACL and mode to the new file, and keeps the on-disk spelling of the name.
COPYFILE_METADATA includes COPYFILE_STAT, which copied the old modification date onto the new content. Copy only extended attributes and the ACL, and set the mode as before.
7d72404 to
d734590
Compare
|
@oliverames I merged |
Rebased on main now that #377 is merged.
This adds a Files service for folders you choose in Settings. Clients can list, read, stat and search inside them. With "Allow writes" on, which is off by default for Files, they can also write, append, make folders, move, and move things to the Trash.
files_trashnever deletes anything for good.files_writereplacing an existing file does replace its content, which is why it needs the caller's last-seen modified time or hash, oroverwrite.Why
Clients often need a few documents, not the whole disk. A service limited to folders the person adds, with changes switched off until they ask for them, lets a client work with files without broader access.
What changed
files_roots,files_list,files_stat,files_readandfiles_search, and the write toolsfiles_write,files_append,files_mkdir,files_moveandfiles_trash..., absolute paths and links that point out of a folder are refused.files_writerefuses to replace an existing file unless the caller passes the modified time or SHA-256 it last saw, or setsoverwrite.files_moveandfiles_trashalso check the item's name on disk before acting.writesEnabledByDefaultis false for Files). They are not listed while it is off, and a direct call is refused.Review fixes
files_statno longer unwrapscanonicalComponents.last!for a link that resolves to the shared root: an empty canonical path is the root itself. A test covers it.files_trashdoes not report success whenF_GETPATHfails; it reports that the result could not be confirmed. If putting a swapped item back fails, the error is reported instead of dropped.writecloses its output descriptor whenwriteAllthrows, on both the replace and the create path.files_appendrefuses a file with more than one hard link, and thefiles_trashrecovery path is exercised by a test.ſ) slipped past the name check, becauselowercased()doesn't fold it and APFS opens it as the real library. Names are now compared after folding, and move and trash check the on-disk path as well.Testing
swift format lint --strict -r .is clean.imcp-serverTests: 359 tests, 1 skipped (pre-existing), 0 failures.FilesTestsincludes stat through a link to the root, the post-trash recovery, the long-s Photos library spelling, and a replace that keeps a file's tags, mode and name and updates its modification date. One Home helper timing test failed once while other builds were running and passed when run again.files_list,files_read(content matched byte for byte),files_write(created a file), andfiles_trash(the file went to the Trash and was still there, not deleted). The write tools ran with Allow writes on; the originals were untouched.Not verified