-2

I need to make sure that my files are written atomically.

Is the same true of folders? Is it impossible that they can be partially written?

I've looked through the documentation of createDirectory(at:withIntermediateDirectories:attributes:) and I cannot see if the method is atomic, or whether there is any possibility that the operation could fail.

Can createDirectory(at:withIntermediateDirectories:attributes:) fail part way through?

Rob
  • 415,655
  • 72
  • 787
  • 1,044
WishIHadThreeGuns
  • 1,225
  • 3
  • 17
  • 37
  • the method throws. Just handle the error – Leo Dabus Oct 05 '19 at 12:49
  • when you ask about atomically/non then there should be a thing that you afraid from a thread operation , it can't happen that control goes to the next line after create inside `try` and there are some files still be in create – Shehata Gamal Oct 05 '19 at 13:20

1 Answers1

1

You say:

I cannot see if the method is atomic

It’s generally an “all or nothing” style of interaction (i.e. you either have a valid file URL or not; you have permission to create directories or not), but given the lack of any formal assurances, I would not assume it’s technically atomic.

But so what if it’s not? It doesn’t have the same implications of an incomplete file-save operation. But regarding directory creation, all you need to know is whether it failed or succeeded (i.e. did it throw an error or not).

You then ask:

... or whether there is any possibility that the operation could fail

Well, obviously, if it can throw errors, it can fail.

Just try to create a directory in a folder to which you don’t have permissions. You’ll see it fail.

Rob
  • 415,655
  • 72
  • 787
  • 1,044