Skip to content

Error "Is a directory" when reopening existing store #138

@pnewell

Description

@pnewell

I've been getting the following error any time I try to reinitialize a store that was previously created. Creating and using a store the first time always works, but if I try to reuse the same URL when rebuilding it always fails with this error:

CodableDatastoreTest/CodableDatastoreTestApp.swift:18: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=256 "The file “2023-07-13 20-58-15 29023E6541A4E39A.snapshot” couldn’t be opened." UserInfo={NSFilePath=/Users/_______/Library/Developer/CoreSimulator/Devices/B6EABA41-EBF0-46A4-8A33-0150DDA84DD2/data/Containers/Data/Application/505B0923-E569-441A-862C-351FA816B866/tmp/73B58D72-6462-4C31-B5B9-FF5DCF5C085F-19496-000005FDA764CEDA/Snapshots/2023/07-13/20-58/2023-07-13 20-58-15 29023E6541A4E39A.snapshot, NSUnderlyingError=0x600000c98660 {Error Domain=NSPOSIXErrorDomain Code=21 "Is a directory"}}

I even copied the DiskPersistenceDatastoreTests file and tried to run it twice with a static URL and get the same error

Example func that works the first time and successfully persists and then fails with above error when trying to build and run a second time

func write() {
        let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.pnewelljr.CodableDatastoreTest")!.appending(path: "Store", directoryHint: .isDirectory)
        let persistence = try DiskPersistence(readWriteURL: url)
        try await persistence.createPersistenceIfNecessary()

        let datastore = Datastore.JSONStore(
            persistence: persistence,
            key: "test",
            version: Version.zero,
            migrations: [
                .zero: { data, decoder in
                    try decoder.decode(TestStruct.self, from: data)
                }
            ]
        )
       try await datastore.warm()
      
        
        try await datastore.persist(TestStruct(id: "3", value: "My name is Dimitri"))
        try await datastore.persist(TestStruct(id: "1", value: "Hello, World!"))
        try await datastore.persist(TestStruct(id: "2", value: "Twenty Three is Number One"))

        let count = try await datastore.count
}

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