Skip to content

Delete can remove an empty directory that appears between its stat and its removal #3

Open

Description

@vinniefalco

Delete asks the Host what the path names, and then asks it to remove the path. Those are two requests, and the Host can run other work between them. If something changes the path in that gap, Delete can remove something it meant to refuse.

What happens

crates/plugin-std/src/rm.rs calls source.stat(path), refuses a directory with a sentence, and then calls source.remove(path). The only removal in the contract is ToolCall::remove(path, recursive), and it takes a file, a link, or a directory with no entries. So the refusal of a directory has to come from the stat, and the stat is a separate request.

If another task replaces the file at path with a directory with no entries after the stat and before the removal, the removal takes that directory. Delete promises that it removes no directory. The docs in rm.rs and lib.rs already say this.

It cannot remove a directory that has entries, because the call passes recursive: false. The loss is limited to an empty directory.

Why it is open

Delete cannot close the gap with what the contract has today. Closing it takes a removal that fails when the path is a directory, in one request. Something like ToolCall::remove_file(path), or a directories: bool flag on remove, would do it. That is a change to runvil-plugin-api and to the Host side in runvil-harness, so it is not a change std can make alone.

Where it came up

What a fix needs

  • A file-only removal in the contract (runvil-plugin-api), and in the Harness that performs it.
  • Delete calls it and drops the stat, or keeps the stat only to word the answer for a link.
  • A test that holds the case: the path becomes an empty directory between the two requests, and Delete leaves it.
  • The docs in rm.rs and lib.rs lose the sentence about the window.

Not covered

A policy that refuses the removal still refuses it. This is about the type of the thing at the path, and nothing else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions