in mxs-copy-components/src/main/scala/com/gu/multimedia/mxscopy/helpers/MatrixStoreHelper.scala [110:148]
def metadataFromFilesystem(file:File):Try[MxsMetadata] = Try {
val path = file.getAbsoluteFile.toPath
val mimeType = Option(Files.probeContentType(file.toPath))
val fsAttrs = Files.readAttributes(path,"*",LinkOption.NOFOLLOW_LINKS).asScala
val maybeCtime = fsAttrs.get("creationTime").map(value=>ZonedDateTime.ofInstant(value.asInstanceOf[FileTime].toInstant,ZoneId.of("UTC")))
val nowTime = ZonedDateTime.now()
val uid = Files.getAttribute(path, "unix:uid", LinkOption.NOFOLLOW_LINKS).asInstanceOf[Int]
MxsMetadata(
stringValues = Map(
"MXFS_FILENAME_UPPER" -> path.getFileName.toString.toUpperCase,
"MXFS_FILENAME"->path.getFileName.toString,
"MXFS_PATH"->path.toString,
"MXFS_USERNAME"->uid.toString, //stored as a string for compatibility. There seems to be no easy way to look up the numeric UID in java/scala
"MXFS_MIMETYPE"->mimeType.getOrElse("application/octet-stream"),
"MXFS_DESCRIPTION"->s"File ${path.getFileName.toString}",
"MXFS_PARENTOID"->"",
"MXFS_FILEEXT"->getFileExt(path.getFileName.toString).getOrElse("")
),
boolValues = Map(
"MXFS_INTRASH"->false,
),
longValues = Map(
"DPSP_SIZE"->file.length(),
"MXFS_MODIFICATION_TIME"->fsAttrs.get("lastModifiedTime").map(_.asInstanceOf[FileTime].toMillis).getOrElse(0),
"MXFS_CREATION_TIME"->fsAttrs.get("creationTime").map(_.asInstanceOf[FileTime].toMillis).getOrElse(0),
"MXFS_ACCESS_TIME"->fsAttrs.get("lastAccessTime").map(_.asInstanceOf[FileTime].toMillis).getOrElse(0),
),
intValues = Map(
"MXFS_CREATIONDAY"->maybeCtime.map(ctime=>ctime.getDayOfMonth).getOrElse(0),
"MXFS_COMPATIBLE"->1,
"MXFS_CREATIONMONTH"->maybeCtime.map(_.getMonthValue).getOrElse(0),
"MXFS_CREATIONYEAR"->maybeCtime.map(_.getYear).getOrElse(0),
"MXFS_CATEGORY"->categoryForMimetype(mimeType)
)
)
}