# File attributes unimplemented in Linux?

**URL:** <https://forums.swift.org/t/file-attributes-unimplemented-in-linux/43943>\
**Category:** Core Libraries\
**Tags:** linux\
**Created:** [January 17, 2021, 9:33pm UTC](https://forums.swift.org/t/file-attributes-unimplemented-in-linux/43943 "2021-01-17T21:33:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![William\_Dillon2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/william_dillon2/32/297_2.png) [@William\_Dillon2](https://forums.swift.org/u/William_Dillon2)\
**Post date:** [January 17, 2021, 9:33pm UTC](https://forums.swift.org/t/file-attributes-unimplemented-in-linux/43943/1 "2021-01-17T21:33:28Z")

</div>

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 [swift.org](http://swift.org) on Ubuntu 20.4.

```swift
//
// 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
}

```

---

<div class="post-metadata">

**Author:** ![William\_Dillon2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/william_dillon2/32/297_2.png) [@William\_Dillon2](https://forums.swift.org/u/William_Dillon2)\
**Post date:** [January 17, 2021, 10:00pm UTC](https://forums.swift.org/t/file-attributes-unimplemented-in-linux/43943/2 "2021-01-17T22:00:50Z")

</div>

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)""`

---

<div class="post-metadata">

**Author:** ![benrimmington](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/benrimmington/32/695_2.png) [@benrimmington](https://forums.swift.org/u/benrimmington)\
**Post date:** [January 18, 2021, 10:28am UTC](https://forums.swift.org/t/file-attributes-unimplemented-in-linux/43943/3 "2021-01-18T10:28:10Z")

</div>

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

[https://github.com/apple/swift-corelibs-foundation/pull/2904](https://github.com/apple/swift-corelibs-foundation/pull/2904)

If this is the same issue on Ubuntu 20.4, there's a possible workaround [here](https://bugs.swift.org/browse/SR-13300?focusedCommentId=59323&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-59323) (i.e. rounding dates to the nearest second).

---

<div class="post-metadata">

**Author:** ![William\_Dillon2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/william_dillon2/32/297_2.png) [@William\_Dillon2](https://forums.swift.org/u/William_Dillon2)\
**Post date:** [January 18, 2021, 4:19pm UTC](https://forums.swift.org/t/file-attributes-unimplemented-in-linux/43943/4 "2021-01-18T16:19:37Z")

</div>

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!
