Skip to content

Commit

Permalink
File update metadata API
Browse files Browse the repository at this point in the history
  • Loading branch information
pathikrit committed Jan 16, 2017
1 parent 18c9cd5 commit c3d6595
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ file.size // for a directory, computes the directory size
file.posixAttributes / file.dosAttributes // see file.attributes
file.isEmpty // true if file has no content (or no children if directory) or does not exist
file.isParentOf / file.isChildOf / file.isSiblingOf / file.siblings
file("dos:system") = true // set custom meta-data for file (similar to Files.setAttribute)
```
All the above APIs let you specify the [`LinkOption`](http://docs.oracle.com/javase/8/docs/api/java/nio/file/LinkOption.html) either directly:
```scala
Expand Down
15 changes: 14 additions & 1 deletion core/src/main/scala/better/files/File.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package better.files

import java.io.{File => JFile, _}
import java.net.URI
import java.nio.channels.{OverlappingFileLockException, AsynchronousFileChannel, FileChannel, NonWritableChannelException, NonReadableChannelException}
import java.nio.channels._
import java.nio.file._, attribute._
import java.security.MessageDigest
import java.time.Instant
Expand Down Expand Up @@ -388,6 +388,19 @@ class File private(val path: Path) {
algorithm.digest()
}

/**
* Set a file attribute e.g. file("dos:system") = true
*
* @param attribute
* @param value
* @param linkOptions
* @return
*/
def update(attribute: String, value: Any)(implicit linkOptions: File.LinkOptions = File.LinkOptions.default): this.type = {
Files.setAttribute(path, attribute, value, linkOptions : _*)
this
}

/**
* @return checksum of this file (or directory) in hex format
*/
Expand Down

0 comments on commit c3d6595

Please sign in to comment.