File attributes unimplemented in Linux?

Hi All,

I'm porting a Mac application that gets/sets file creation and modification dates via FileManager. I get an inscrutable thrown error in setAttributes (when the attributes dictionary is non-empty), and an empty response to attributesOfItem. Is it expected that these are unimplemented, or am I missing something. I'm using the latest 5.3 on on Ubuntu 20.4.

//  FileFixer.swift
//  FixEncodedDate
//  Created by William Dillon on 1/9/21.

import Foundation

public func fixFileDate(url: URL, date: Date) throws {
    try FileManager().setAttributes(
            [FileAttributeKey.creationDate: date,
             FileAttributeKey.modificationDate: date],
            ofItemAtPath: url.path

public func getFileDate(url: URL) throws -> Date? {
    let attributes = try FileManager().attributesOfItem(atPath: url.path)

    return attributes[FileAttributeKey.creationDate] as? Date

Reading through the code in GitHub, I can see that creationDate is unimplemented, so I removed that key in both instances and it still throws:

<EXPR>:0: error: LibTimeTurnerTests.testDateFixer : threw error "Error Domain=NSCocoaErrorDomain Code=512 "(null)""

There was a bug (fixed in Swift 5.4) where setting the modification date could fail:

If this is the same issue on Ubuntu 20.4, there's a possible workaround here (i.e. rounding dates to the nearest second).

Ah! That explains why when I was copy/pasting code into my project to debug it I couldn't reproduce... I was copying from main. Thanks!

Terms of Service

Privacy Policy

Cookie Policy