Skip to content

Commit

Permalink
Feat: Remove root archive file system provider
Browse files Browse the repository at this point in the history
Now that ArchiveReader supports SeekableByteChannel.

Fixes: #1140
  • Loading branch information
zhanghai committed Feb 28, 2024
1 parent d74b227 commit 7882c21
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 851 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,60 @@
/*
* Copyright (c) 2018 Hai Zhang <dreaming.in.code.zh@gmail.com>
* Copyright (c) 2019 Hai Zhang <dreaming.in.code.zh@gmail.com>
* 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)
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
/*
* Copyright (c) 2018 Hai Zhang <dreaming.in.code.zh@gmail.com>
* Copyright (c) 2019 Hai Zhang <dreaming.in.code.zh@gmail.com>
* 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
}
Loading

0 comments on commit 7882c21

Please sign in to comment.