mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Scan refactor (#1816)
* Add file scanner * Scan scene changes * Split scan files * Generalise scan * Refactor ffprobe * Refactor ffmpeg encoder * Move scene scan code to scene package * Move matchExtension to utils * Refactor gallery scanning * Refactor image scanning * Prevent race conditions on identical hashes * Refactor image thumbnail generation * Perform count concurrently * Allow progress increment before total set * Make progress updates more frequent
This commit is contained in:
64
pkg/file/zip.go
Normal file
64
pkg/file/zip.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"io"
|
||||
"io/fs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const zipSeparator = "\x00"
|
||||
|
||||
type zipFile struct {
|
||||
zipPath string
|
||||
zf *zip.File
|
||||
}
|
||||
|
||||
func (f *zipFile) Open() (io.ReadCloser, error) {
|
||||
return f.zf.Open()
|
||||
}
|
||||
|
||||
func (f *zipFile) Path() string {
|
||||
// TODO - fix this
|
||||
return ZipFilename(f.zipPath, f.zf.Name)
|
||||
}
|
||||
|
||||
func (f *zipFile) FileInfo() fs.FileInfo {
|
||||
return f.zf.FileInfo()
|
||||
}
|
||||
|
||||
func ZipFile(zipPath string, zf *zip.File) SourceFile {
|
||||
return &zipFile{
|
||||
zipPath: zipPath,
|
||||
zf: zf,
|
||||
}
|
||||
}
|
||||
|
||||
func ZipFilename(zipFilename, filenameInZip string) string {
|
||||
return zipFilename + zipSeparator + filenameInZip
|
||||
}
|
||||
|
||||
// IsZipPath returns true if the path includes the zip separator byte,
|
||||
// indicating it is within a zip file.
|
||||
func IsZipPath(p string) bool {
|
||||
return strings.Contains(p, zipSeparator)
|
||||
}
|
||||
|
||||
// ZipPathDisplayName converts an zip path for display. It translates the zip
|
||||
// file separator character into '/', since this character is also used for
|
||||
// path separators within zip files. It returns the original provided path
|
||||
// if it does not contain the zip file separator character.
|
||||
func ZipPathDisplayName(path string) string {
|
||||
return strings.Replace(path, zipSeparator, "/", -1)
|
||||
}
|
||||
|
||||
func ZipFilePath(path string) (zipFilename, filename string) {
|
||||
nullIndex := strings.Index(path, zipSeparator)
|
||||
if nullIndex != -1 {
|
||||
zipFilename = path[0:nullIndex]
|
||||
filename = path[nullIndex+1:]
|
||||
} else {
|
||||
filename = path
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user