Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ sealed class Action {
ZipEntry(
if (!preserveStructure) srcFileName
else srcFile.pathRelativeTo(src)!!,
),
).apply {
time = srcFile.lastModified
srcFile.creationTime?.let { creationTime = it }
},
)
srcFile.getInputStream(context).use { src ->
if (src == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import net.schmizz.sshj.sftp.RemoteResourceInfo
import java.io.BufferedOutputStream
import java.net.URLConnection
import java.nio.file.Files
Expand Down Expand Up @@ -112,7 +111,6 @@ sealed class RemoteAction : Action() {
}
} else null

val srcRemoteFiles = mutableListOf<RemoteResourceInfo>()
val tempDir =
withContext(Dispatchers.IO) { Files.createTempDirectory("fileflow-sftp-temp-downloads") }

Expand Down Expand Up @@ -156,7 +154,7 @@ sealed class RemoteAction : Action() {

val destLocalPaths = mutableListOf<String?>()

for ((srcFile, remoteFileInfo) in srcFiles) {
for ((srcFile, _) in srcFiles) {
val srcFileName = srcFile.name ?: continue
val destFileName = getDestFileName(srcFile)
val relativePath = srcFile.parent!!.pathRelativeTo(src)
Expand Down Expand Up @@ -233,8 +231,6 @@ sealed class RemoteAction : Action() {
srcFile.path,
"${destSubDir.trimEnd('/')}/$destFileName",
)
if (!keepOriginal && remoteFileInfo != null)
rm(remoteFileInfo.path)

true
} catch (e: Exception) {
Expand Down Expand Up @@ -275,13 +271,14 @@ sealed class RemoteAction : Action() {
}.distinct().toTypedArray(),
null,
) { path, _ -> Logger.d("RemoteAction", "Scanned media at $path") }
} else if (!keepOriginal) {
SFTP.runOn(srcServer!!) {
for (file in srcRemoteFiles) {
}
if (srcServer != null && !keepOriginal) {
SFTP.runOn(srcServer) {
for ((_, remoteFileInfo) in srcFiles) {
try {
rm(file.path)
rm(remoteFileInfo!!.path)
} catch (e: Exception) {
Logger.e("RemoteAction", "Failed to delete ${file.name}", e)
Logger.e("RemoteAction", "Failed to delete ${remoteFileInfo?.name}", e)
}
}
}
Expand Down Expand Up @@ -451,6 +448,7 @@ sealed class RemoteAction : Action() {
&& it.name != null
&& Regex(srcFileNamePattern).matches(it.name!!)
}
?.map { it to null }
?: return
} else {
SFTP.runOn(srcServer) {
Expand All @@ -464,7 +462,7 @@ sealed class RemoteAction : Action() {
tempDir.resolve(Paths.get(src).relativize(Paths.get(it.path)))
Files.createDirectories(tempFilePath.parent)
get(it.path, tempFilePath.toString())
File.fromPath(context, tempFilePath.toString())
File.fromPath(context, tempFilePath.toString())!! to it
} catch (e: Exception) {
Logger.e("RemoteAction", "Failed to fetch ${it.name}", e)
null
Expand All @@ -474,7 +472,7 @@ sealed class RemoteAction : Action() {
}

ZipOutputStream(BufferedOutputStream(destFile.getOutputStream(context))).use { dest ->
for (srcFile in srcFiles) {
for ((srcFile, remoteFileInfo) in srcFiles) {
val srcFileName = srcFile.name ?: continue
Logger.i("RemoteAction", "Adding $srcFileName to archive")

Expand All @@ -483,7 +481,14 @@ sealed class RemoteAction : Action() {
ZipEntry(
if (!preserveStructure) srcFileName
else srcFile.pathRelativeTo(src)!!,
),
).apply {
if (remoteFileInfo != null) {
time = remoteFileInfo.attributes.mtime * 1000
} else {
time = srcFile.lastModified
srcFile.creationTime?.let { creationTime = it }
}
},
)
srcFile.getInputStream(context).use { src ->
if (src == null) {
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/co/adityarajput/fileflow/utils/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import java.net.URLDecoder
import java.nio.file.FileAlreadyExistsException
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.attribute.FileTime
import java.io.File as IOFile

sealed class File {
Expand Down Expand Up @@ -57,6 +59,8 @@ sealed class File {

override val parent get() = documentFile.parentFile?.let { SAFFile(it) }

override val creationTime = null

override val lastModified get() = documentFile.lastModified()

override val length get() = documentFile.length()
Expand Down Expand Up @@ -151,6 +155,15 @@ sealed class File {

override val parent: File? get() = ioFile.parentFile?.let { FSFile(it) }

override val creationTime
get() = try {
Files.readAttributes(ioFile.toPath(), BasicFileAttributes::class.java)
.creationTime()
} catch (e: Exception) {
Logger.w("Files", "Failed to get file creation time", e)
null
}

override val lastModified get() = ioFile.lastModified()

override val length get() = ioFile.length()
Expand Down Expand Up @@ -264,6 +277,8 @@ sealed class File {

abstract val parent: File?

abstract val creationTime: FileTime?

abstract val lastModified: Long

abstract val length: Long
Expand Down
1 change: 1 addition & 0 deletions metadata/en-US/changelogs/9.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
• feat: Add an optional "name" field to rules (visit app settings to enable)
• feat: Add a "path" special reference for templates (check project wiki for details)
• feat: Add opt-in email-based crash reporting using ACRA
• feat: Preserve meta timestamps when zipping
Loading