A dispatch source that monitors directory changes is not called when updating file sizes

I wrote a subclass of UITableViewController that lists the files in a directory group along with their respective sizes. It is also updated when there are any changes to these directories. The class uses DispatchSourceto "browse" directories. Here is the code that does this:

    for dir in directories {
        let fd = dir.withUnsafeFileSystemRepresentation { (filenamePointer) -> Int32 in
            // vfw_open is a wrapper function for open()
            return vfw_open(filenamePointer, O_EVTONLY)
        }

        guard fd != 0 else {
            return
        }

        let watcher = DispatchSource.makeFileSystemObjectSource(fileDescriptor: fd,
                                                                 eventMask: DispatchSource.FileSystemEvent.write,
                                                                 queue: DispatchQueue.global(qos: .utility))

        watcher.setEventHandler { [weak self] in
            DispatchQueue.main.async {
                self?.updateFileList()
            }
        }

        watcher.setCancelHandler() {
            close(fd)
        }

        watcher.resume()
    }

updateFileList, . , . , , updateFileList . , 0 . , , updateFileList , , . ?

+5
1

, , . - . ( , ), , . .

, .

+2

Source: https://habr.com/ru/post/1680293/


All Articles