-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - copy file without touching source
- Loading branch information
Showing
5 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...in/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/CopyFile.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations | ||
|
||
import akka.http.scaladsl.model.Uri | ||
import cats.effect.{Blocker, ContextShift, IO} | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.model.FileAttributes.FileAttributesOrigin.Client | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.model.{FileAttributes, FileDescription} | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.Storage.DiskStorage | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.disk.DiskStorageSaveFile.initLocation | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.remote.RemoteDiskStorageLinkFile | ||
|
||
import java.nio.file.{CopyOption, Path, StandardCopyOption} | ||
import scala.concurrent.ExecutionContext | ||
|
||
object CopyFile { | ||
|
||
def copyLocal(destDesc: FileDescription, destStorage: DiskStorage, sourceAttr: FileAttributes): IO[FileAttributes] = { | ||
val ec = ExecutionContext.global | ||
implicit val cs: ContextShift[IO] = IO.contextShift(ec) | ||
val blocker: Blocker = Blocker.liftExecutionContext(ec) | ||
val source: Path = Path.of("/") | ||
val dest: Path = Path.of("/") | ||
val flags: Seq[CopyOption] = Seq(StandardCopyOption.COPY_ATTRIBUTES) | ||
|
||
for { | ||
(fullPath, relativePath) <- initLocation(destStorage.project, destStorage.value, destDesc.uuid, destDesc.filename) | ||
createdFilePath <- fs2.io.file.copy[IO](blocker, source, dest, flags) | ||
_ <- IO.raiseUnless(createdFilePath == fullPath)(new Exception("Created file not consistent with path")) | ||
} yield FileAttributes( | ||
uuid = destDesc.uuid, | ||
location = Uri(fullPath.toUri.toString), | ||
path = Uri.Path(relativePath.toString), | ||
filename = destDesc.filename, | ||
mediaType = destDesc.mediaType, | ||
bytes = sourceAttr.bytes, | ||
digest = sourceAttr.digest, | ||
origin = Client | ||
) | ||
} | ||
|
||
def copyRemote( | ||
sourcePath: Uri.Path, | ||
destDesc: FileDescription | ||
): IO[FileAttributes] = ??? | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters