{"action":"created","issue":{"url":"https://api.github.com/repos/Gabriel439/Haskell-Turtle-Library/issues/98","labels_url":"https://api.github.com/repos/Gabriel439/Haskell-Turtle-Library/issues/98/labels{/name}","comments_url":"https://api.github.com/repos/Gabriel439/Haskell-Turtle-Library/issues/98/comments","events_url":"https://api.github.com/repos/Gabriel439/Haskell-Turtle-Library/issues/98/events","html_url":"https://github.com/Gabriel439/Haskell-Turtle-Library/issues/98","id":101719361,"number":98,"title":"Clarify intended use of `using`","user":{"login":"rpglover64","id":233689,"avatar_url":"https://avatars.githubusercontent.com/u/233689?v=3","gravatar_id":"","url":"https://api.github.com/users/rpglover64","html_url":"https://github.com/rpglover64","followers_url":"https://api.github.com/users/rpglover64/followers","following_url":"https://api.github.com/users/rpglover64/following{/other_user}","gists_url":"https://api.github.com/users/rpglover64/gists{/gist_id}","starred_url":"https://api.github.com/users/rpglover64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpglover64/subscriptions","organizations_url":"https://api.github.com/users/rpglover64/orgs","repos_url":"https://api.github.com/users/rpglover64/repos","events_url":"https://api.github.com/users/rpglover64/events{/privacy}","received_events_url":"https://api.github.com/users/rpglover64/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-08-18T18:22:55Z","updated_at":"2015-08-24T17:43:56Z","closed_at":"2015-08-24T03:17:11Z","body":"```\r\n*Main> sh $ using (mktemp \".\" \"foo\") >>= \\(a,h) -> outhandle h (return \"asdf\") >> stdout (input a)\r\n*** Exception: ./foo1804289383846930886: openFile: resource busy (file is locked)\r\n```\r\nI expect this code to print \"asdf\"; I assume that my expectation is wrong and that this is not a bug, but I don't see anything in the documentation to explain how I would accomplish the intended behavior."},"comment":{"url":"https://api.github.com/repos/Gabriel439/Haskell-Turtle-Library/issues/comments/134313326","html_url":"https://github.com/Gabriel439/Haskell-Turtle-Library/issues/98#issuecomment-134313326","issue_url":"https://api.github.com/repos/Gabriel439/Haskell-Turtle-Library/issues/98","id":134313326,"user":{"login":"rpglover64","id":233689,"avatar_url":"https://avatars.githubusercontent.com/u/233689?v=3","gravatar_id":"","url":"https://api.github.com/users/rpglover64","html_url":"https://github.com/rpglover64","followers_url":"https://api.github.com/users/rpglover64/followers","following_url":"https://api.github.com/users/rpglover64/following{/other_user}","gists_url":"https://api.github.com/users/rpglover64/gists{/gist_id}","starred_url":"https://api.github.com/users/rpglover64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpglover64/subscriptions","organizations_url":"https://api.github.com/users/rpglover64/orgs","repos_url":"https://api.github.com/users/rpglover64/repos","events_url":"https://api.github.com/users/rpglover64/events{/privacy}","received_events_url":"https://api.github.com/users/rpglover64/received_events","type":"User","site_admin":false},"created_at":"2015-08-24T17:43:56Z","updated_at":"2015-08-24T17:43:56Z","body":"Right. `Managed` embeds into `Shell`; I should have realized.\r\n\r\nThe cleaned up code you presented still has the same TOCTOU bug, though, if the attacker swaps out the file between `mktemp` and `output` or between `output` and `input`; the nominally \"proper\" way to do this would be to return a file handle (like `mktemp` used to), possibly without the file name (this is probably why [`System.IO.openTempFile`](https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#v:openTempFile) has the return type it does).\r\n\r\n> The direct answer your question is to just do this\r\n\r\nIs there a way of ensuring that the file is deleted after `example` (since it doesn't happen automatically)? e.g.\r\n\r\n```haskell\r\nexample2 = do\r\n    output \"/tmp/foo1234\" \"asdf\"\r\n    example\r\n    example\r\n    view $ find (prefix \"/tmp/foo\") \"/tmp\"\r\n    -- I would like this to print only `FilePath \"/tmp/foo1234\"`\r\n```\r\n\r\nThat's what I was looking for in `with`."}}