# std.fs: Implement cross-platform metadata API · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/11b4cc589c85b6330824ac9a64bfb0829cc1adb0)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 11b4cc589c85b6330824ac9a64bfb0829cc1adb0

Requested commit: 11b4cc589c85b6330824ac9a64bfb0829cc1adb0

Commit: 11b4cc589c85b6330824ac9a64bfb0829cc1adb0

Tree: e7d013c8c80ce78c1b12285ddee4fd5f2cc41822

Author: ominitay

Committer: ominitay

## Message

```
std.fs: Implement cross-platform metadata API

Implements a cross-platform metadata API, aiming to reduce unnecessary Unix-dependence of the `std.fs` api. Presently, all OSes beside Windows are treated as Unix; this is likely the best way to treat things by default, instead of explicitly listing each Unix-like OS.

Platform-specific operations are not provided by `File.Metadata`, and instead are to be accessed from `File.Metadata.inner`.

Adds:

- File.setPermissions() : Sets permission of a file according to a `Permissions` struct (not available on WASI)

- File.Permissions : A cross-platform representation of file permissions
  - Permissions.readOnly() : Returns whether the file is read-only
  - Permissions.setReadOnly() : Sets whether the file is read-only
  - Permissions.unixSet() : Sets permissions for a class (UNIX-only)
  - Permissions.unixGet() : Checks a permission for a class (UNIX-only)
  - Permissions.unixNew() : Returns a new Permissions struct to represent the passed mode (UNIX-only)

- File.Metadata : A cross-platform representation of file metadata
  - Metadata.size() : Returns the size of a file
  - Metadata.permissions() : Returns a `Permissions` struct, representing permissions on the file
  - Metadata.kind() : Returns the `Kind` of the file
  - Metadata.accessed() : Returns the time the file was last accessed
  - Metadata.modified() : Returns the time the file was last modified
  - Metadata.created() : Returns the time the file was created (this is an optional, as the underlying filesystem, or OS may not support this)

Methods of `File.Metadata` are also available for the below, so I won't repeat myself
The below may be used for platform-specific functionality

- File.MetadataUnix : The internal implementation of `File.Metadata` on Unices

- File.MetadataLinux : The internal implementation of `File.Metadata` on Linux

- File.MetadataWindows : The implementation of `File.Metadata` on Windows

```

## Parents

- [b2610649fcf43c678fd81f3bef71f3ba42ee3606](https://git.cafe/gitcafe/zig/commit/b2610649fcf43c678fd81f3bef71f3ba42ee3606?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/11b4cc589c85b6330824ac9a64bfb0829cc1adb0?format=markdown)
