Skip to content

Consider a variant of deleteFile that on Windows retries x times before giving up #96

Closed

Description

@Mistuke

As discussed in haskell/hsc2hs#25 there are various services on Windows that can keep a file open for a fraction of time, such as indexer or AV services. That means that deleteFile may fail temporarily.

It's a reasonably common idiom, SQLlite for instance does so as well https://www.sqlite.org/src/info/89f1848d7f and we do it in the GHC testsuite and now hsc2hs to avoid a race condition with the file deletion.

Would it be perhaps handy to have such a function in Directory?

Activity

  1. added
    type: (3) feature request
    on Jun 22, 2019
  2. Rufflewind commented on Jun 22, 2019

    @Rufflewind
    Member

    It's not a very elegant solution, but I guess it's kind of needed on Windows. I would suggest making a somewhat generic retry function if possible, as there are many variants of removeFileThing:

    retryOnPermissionError :: {- numRetries -} Int -> IO a -> IO a
  3. Rufflewind commented on Nov 12, 2019

    @Rufflewind
    Member

    Is there still interest in this feature?

  4. Mistuke commented on Nov 13, 2019

    @Mistuke
    ContributorAuthor

    Is there still interest in this feature?

    Yes, it's used in GHC, hsc2hs, cabal and GHC's testsuite. So it would allow us to align those implementations and I believe it's useful for third parties as well. But I honestly don't know when I would personally have the time to implement this.

  5. hasufell commented on Jan 9, 2020

    @hasufell
    Member

    retryOnPermissionError :: {- numRetries -} Int -> IO a -> IO a

    I think the wording is problematic. Afais, the exceptions to retry on are ERROR_LOCK_VIOLATION and ERROR_SHARING_VIOLATION, which are very specific. And we don't know if that will change or if there are more use cases for this for some users. Code-paths that rely on exception types are very very fragile.

    I would go so far to say this doesn't belong in this library, but is a generic exception handling function and already exists in various forms, such as retryBool.

    The documentation of removeFile should simply document this behavior. That's what the python sdtlib does as well.

  6. Rufflewind commented on Feb 14, 2020

    @Rufflewind
    Member

    I'm inclined to agree with @hasufell that this might be getting a bit out of scope for this library. A general retry function probably belongs to System.IO.Exception or similar.

    Closing this issue for now. Let me know if there are any concerns.

  7. added
    type: (9) out of scope
    and removed
    type: (3) feature request
    on Feb 14, 2020
  8. added a commit that references this issue on Mar 12, 2020
  9. added a commit that references this issue on Mar 13, 2020
  10. Rufflewind commented on Jul 19, 2020

    @Rufflewind
    Member

    It looks like there's an algorithm for deleting directories on Windows without the need for retries: #110

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

    type: (9) out of scope

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions