-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Remove root archive file system provider
Now that ArchiveReader supports SeekableByteChannel. Fixes: #1140
- Loading branch information
Showing
11 changed files
with
529 additions
and
851 deletions.
There are no files selected for viewing
67 changes: 45 additions & 22 deletions
67
app/src/main/java/me/zhanghai/android/files/provider/archive/ArchiveFileAttributeView.kt
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 |
---|---|---|
@@ -1,37 +1,60 @@ | ||
/* | ||
* Copyright (c) 2018 Hai Zhang <[email protected]> | ||
* Copyright (c) 2019 Hai Zhang <[email protected]> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.provider.archive | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
import me.zhanghai.android.files.provider.root.RootablePosixFileAttributeView | ||
import me.zhanghai.android.files.util.readParcelable | ||
import java8.nio.file.Path | ||
import java8.nio.file.attribute.FileTime | ||
import me.zhanghai.android.files.provider.common.ByteString | ||
import me.zhanghai.android.files.provider.common.PosixFileAttributeView | ||
import me.zhanghai.android.files.provider.common.PosixFileModeBit | ||
import me.zhanghai.android.files.provider.common.PosixGroup | ||
import me.zhanghai.android.files.provider.common.PosixUser | ||
import java.io.IOException | ||
|
||
internal class ArchiveFileAttributeView(private val path: Path) : PosixFileAttributeView { | ||
override fun name(): String = NAME | ||
|
||
@Throws(IOException::class) | ||
override fun readAttributes(): ArchiveFileAttributes { | ||
val fileSystem = path.fileSystem as ArchiveFileSystem | ||
val entry = fileSystem.getEntry(path) | ||
return ArchiveFileAttributes.from(fileSystem.archiveFile, entry) | ||
} | ||
|
||
internal class ArchiveFileAttributeView( | ||
private val path: ArchivePath | ||
) : RootablePosixFileAttributeView( | ||
path, LocalArchiveFileAttributeView(path), { RootArchiveFileAttributeView(it, path) } | ||
) { | ||
private constructor(source: Parcel) : this(source.readParcelable<ArchivePath>()!!) | ||
override fun setTimes( | ||
lastModifiedTime: FileTime?, | ||
lastAccessTime: FileTime?, | ||
createTime: FileTime? | ||
) { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun describeContents(): Int = 0 | ||
override fun setOwner(owner: PosixUser) { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun writeToParcel(dest: Parcel, flags: Int) { | ||
dest.writeParcelable(path as Parcelable, flags) | ||
override fun setGroup(group: PosixGroup) { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
companion object { | ||
val SUPPORTED_NAMES = LocalArchiveFileAttributeView.SUPPORTED_NAMES | ||
override fun setMode(mode: Set<PosixFileModeBit>) { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
@JvmField | ||
val CREATOR = object : Parcelable.Creator<ArchiveFileAttributeView> { | ||
override fun createFromParcel(source: Parcel): ArchiveFileAttributeView = | ||
ArchiveFileAttributeView(source) | ||
override fun setSeLinuxContext(context: ByteString) { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun restoreSeLinuxContext() { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
companion object { | ||
private val NAME = ArchiveFileSystemProvider.scheme | ||
|
||
override fun newArray(size: Int): Array<ArchiveFileAttributeView?> = arrayOfNulls(size) | ||
} | ||
val SUPPORTED_NAMES = setOf("basic", "posix", NAME) | ||
} | ||
} |
50 changes: 28 additions & 22 deletions
50
app/src/main/java/me/zhanghai/android/files/provider/archive/ArchiveFileStore.kt
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 |
---|---|---|
@@ -1,36 +1,42 @@ | ||
/* | ||
* Copyright (c) 2018 Hai Zhang <[email protected]> | ||
* Copyright (c) 2019 Hai Zhang <[email protected]> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.provider.archive | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
import java8.nio.file.Path | ||
import me.zhanghai.android.files.provider.root.RootPosixFileStore | ||
import me.zhanghai.android.files.provider.root.RootablePosixFileStore | ||
import java8.nio.file.attribute.FileAttributeView | ||
import me.zhanghai.android.files.file.MimeType | ||
import me.zhanghai.android.files.file.guessFromPath | ||
import me.zhanghai.android.files.provider.common.PosixFileStore | ||
import me.zhanghai.android.files.provider.common.size | ||
import java.io.IOException | ||
|
||
internal class ArchiveFileStore(private val archiveFile: Path) : RootablePosixFileStore( | ||
archiveFile, LocalArchiveFileStore(archiveFile), { RootPosixFileStore(it) } | ||
) { | ||
private constructor(source: Parcel) : this( | ||
source.readParcelable<Parcelable>(Path::class.java.classLoader) as Path | ||
) | ||
internal class ArchiveFileStore(private val archiveFile: Path) : PosixFileStore() { | ||
override fun refresh() {} | ||
|
||
override fun describeContents(): Int = 0 | ||
override fun name(): String = archiveFile.toString() | ||
|
||
override fun writeToParcel(dest: Parcel, flags: Int) { | ||
dest.writeParcelable(archiveFile as Parcelable, flags) | ||
} | ||
override fun type(): String = MimeType.guessFromPath(archiveFile.toString()).value | ||
|
||
companion object { | ||
@JvmField | ||
val CREATOR = object : Parcelable.Creator<ArchiveFileStore> { | ||
override fun createFromParcel(source: Parcel): ArchiveFileStore = | ||
ArchiveFileStore(source) | ||
override fun isReadOnly(): Boolean = true | ||
|
||
override fun newArray(size: Int): Array<ArchiveFileStore?> = arrayOfNulls(size) | ||
} | ||
@Throws(IOException::class) | ||
override fun setReadOnly(readOnly: Boolean) { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun getTotalSpace(): Long = archiveFile.size() | ||
|
||
override fun getUsableSpace(): Long = 0 | ||
|
||
override fun getUnallocatedSpace(): Long = 0 | ||
|
||
override fun supportsFileAttributeView(type: Class<out FileAttributeView>): Boolean = | ||
ArchiveFileSystemProvider.supportsFileAttributeView(type) | ||
|
||
override fun supportsFileAttributeView(name: String): Boolean = | ||
name in ArchiveFileAttributeView.SUPPORTED_NAMES | ||
} |
Oops, something went wrong.