Skip to content

Commit

Permalink
Merge pull request #2622 from armanbilge/feature/files-realpath
Browse files Browse the repository at this point in the history
Implement Files#realPath
  • Loading branch information
mpilquist committed Sep 20, 2021
2 parents eaba366 + eb63175 commit 8ba9dc5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions io/js/src/main/scala/fs2/io/file/FilesPlatform.scala
Expand Up @@ -336,6 +336,9 @@ private[fs2] trait FilesCompanionPlatform {
override def readRange(path: Path, chunkSize: Int, start: Long, end: Long): Stream[F, Byte] =
readStream(path, chunkSize, Flags.Read)(_.setStart(start.toDouble).setEnd((end - 1).toDouble))

def realPath(path: Path): F[Path] =
F.fromPromise(F.delay(fsPromisesMod.realpath(path.toString))).map(Path(_))

override def setFileTimes(
path: Path,
lastModified: Option[FiniteDuration],
Expand Down
3 changes: 3 additions & 0 deletions io/jvm/src/main/scala/fs2/io/file/FilesPlatform.scala
Expand Up @@ -302,6 +302,9 @@ private[file] trait FilesCompanionPlatform {
def openFileChannel(channel: F[FileChannel]): Resource[F, FileHandle[F]] =
Resource.make(channel)(ch => Sync[F].blocking(ch.close())).map(ch => FileHandle.make(ch))

def realPath(path: Path): F[Path] =
Sync[F].blocking(Path.fromNioPath(path.toNioPath.toRealPath()))

def setFileTimes(
path: Path,
lastModified: Option[FiniteDuration],
Expand Down
7 changes: 7 additions & 0 deletions io/shared/src/main/scala/fs2/io/file/Files.scala
Expand Up @@ -270,6 +270,13 @@ sealed trait Files[F[_]] extends FilesPlatform[F] {
*/
def readRange(path: Path, chunkSize: Int, start: Long, end: Long): Stream[F, Byte]

/** Returns the real path i.e. the actual location of `path`.
* The precise definition of this method is implementation dependent but in general
* it derives from this path, an absolute path that locates the same file as this path,
* but with name elements that represent the actual name of the directories and the file.
*/
def realPath(path: Path): F[Path]

/** Sets the last modified, last access, and creation time fields of the specified path.
*
* Times which are supplied as `None` are not modified. E.g., `setTimes(p, Some(t), Some(t), None, false)`
Expand Down

0 comments on commit 8ba9dc5

Please sign in to comment.