Skip to content

Commit dfd7995

Browse files
committed
Fix: Decompress folder retain their original timestamps
1 parent 1fbfc97 commit dfd7995

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

app/src/main/kotlin/org/fossify/filemanager/activities/DecompressActivity.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@ class DecompressActivity : SimpleActivity() {
155155
zipInputStream.setPassword(password?.toCharArray())
156156
}
157157
val buffer = ByteArray(1024)
158+
val foldersTimestamp = mutableListOf<Pair<File, LocalFileHeader>>()
158159

159160
zipInputStream.use {
160161
while (true) {
161162
val entry = zipInputStream.nextEntry ?: break
162163
val filename = filename.substringBeforeLast(".")
163164
val parent = "$destination/$filename"
164165
val newPath = "$parent/${entry.fileName.trimEnd('/')}"
166+
val outputFile = File(newPath)
165167

166168
if (!getDoesFilePathExist(parent)) {
167169
if (!createDirectorySync(parent)) {
@@ -170,10 +172,14 @@ class DecompressActivity : SimpleActivity() {
170172
}
171173

172174
if (entry.isDirectory) {
175+
if (!getDoesFilePathExist(newPath)) {
176+
createDirectorySync(newPath)
177+
}
178+
179+
foldersTimestamp.add(Pair(outputFile,entry))
173180
continue
174-
}
175181

176-
val outputFile = File(newPath)
182+
}
177183

178184
val isVulnerableForZipPathTraversal = !outputFile.canonicalPath.startsWith(parent)
179185
if (isVulnerableForZipPathTraversal) {
@@ -193,7 +199,9 @@ class DecompressActivity : SimpleActivity() {
193199
fos!!.close()
194200
outputFile.setLastModified(entry)
195201
}
196-
202+
for ((folder,header) in foldersTimestamp){
203+
folder.setLastModified((header))
204+
}
197205
toast(R.string.decompression_successful)
198206
finish()
199207
}

0 commit comments

Comments
 (0)