Documentation ¶
Overview ¶
Package fs provides filesystem related constants and functions.
Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.
This program is free software: you can redistribute it and/or modify it under Version 3 of the GNU Affero General Public License (the "AGPL"): <https://docs.photoprism.app/license/agpl> This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. The AGPL is supplemented by our Trademark and Brand Guidelines, which describe how our Brand Assets may be used: <https://www.photoprism.app/trademark>
Feel free to send an email to [email protected] if you have questions, want to support our work, or just want to say hello.
Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>
Index ¶
- Constants
- Variables
- func Abs(name string) string
- func AbsPrefix(fileName string, stripSequence bool) string
- func AddToZip(zipWriter *zip.Writer, filename string) error
- func BasePrefix(fileName string, stripSequence bool) string
- func CacheFileFromReader(fileName string, reader io.Reader) (string, error)
- func CachePath(basePath, fileHash, namespace string, create bool) (cachePath string, err error)
- func CanonicalName(date time.Time, checksum string) string
- func CaseInsensitive(storagePath string) (result bool, err error)
- func Checksum(fileName string) string
- func Copy(src, dest string) (err error)
- func DirIsEmpty(path string) bool
- func Dirs(root string, recursive bool, followLinks bool) (result []string, err error)
- func Download(fileName string, url string) error
- func Ext(name string) string
- func FileExists(fileName string) bool
- func FileExistsNotEmpty(fileName string) bool
- func FileName(fileName, dirName, baseDir, fileExt string) string
- func FileNameHidden(name string) bool
- func FindDir(dirs []string) string
- func Hash(fileName string) string
- func IgnoreCase()
- func IsAnimatedImage(fileName string) bool
- func IsAsciiID(s string) bool
- func IsCanonical(basename string) bool
- func IsDscName(s string) bool
- func IsGenerated(fileName string) bool
- func IsHash(s string) bool
- func IsInt(s string) bool
- func IsUniqueName(s string) bool
- func LowerExt(fileName string) string
- func MimeType(filename string) (mimeType string)
- func MkdirAll(dir string) error
- func ModTime(filePath string) time.Time
- func Move(src, dest string) (err error)
- func NonCanonical(basename string) bool
- func NormalizedExt(fileName string) string
- func PathExists(path string) bool
- func PathWritable(path string) bool
- func ReadLines(fileName string) (lines []string, err error)
- func RelName(fileName, dir string) string
- func RelPrefix(fileName, dir string, stripSequence bool) string
- func Resolve(filePath string) (string, error)
- func SkipWalk(fileName string, isDir, isSymlink bool, done Done, ignore *IgnoreList) (skip bool, result error)
- func StripExt(name string) string
- func StripKnownExt(name string) string
- func StripSequence(fileName string) string
- func SymlinksSupported(storagePath string) (bool, error)
- func TrimExt(ext string) string
- func Unzip(src, dest string) (fileNames []string, err error)
- func Writable(path string) bool
- func WriteFile(fileName string, data []byte) error
- func WriteFileFromReader(fileName string, reader io.Reader) (err error)
- func WriteString(fileName string, s string) error
- func WriteUnixTime(fileName string) (unixTime int64, err error)
- func Zip(filename string, files []string) error
- type Blacklist
- type Blacklists
- type Done
- type FileExtensions
- type FileInfo
- type FileInfos
- type IgnoreItem
- type IgnoreList
- func (l *IgnoreList) AppendItems(dir string, patterns []string) error
- func (l *IgnoreList) ConfigFile(fileName string) error
- func (l *IgnoreList) Dir(dir string) error
- func (l *IgnoreList) Hidden() []string
- func (l *IgnoreList) Ignore(fileName string) bool
- func (l *IgnoreList) Ignored() []string
- func (l *IgnoreList) Reset()
- type IgnoreLogFunc
- type Status
- type Type
- func (t Type) DefaultExt() string
- func (t Type) Equal(s string) bool
- func (t Type) Find(fileName string, stripSequence bool) string
- func (t Type) FindAll(fileName string, dirs []string, baseDir string, stripSequence bool) (results []string)
- func (t Type) FindFirst(fileName string, dirs []string, baseDir string, stripSequence bool) string
- func (t Type) NotEqual(s string) bool
- func (t Type) String() string
- type TypeMap
- type TypesExt
Constants ¶
const ( PPIgnoreFilename = ".ppignore" PPIgnoreAll = "*" PPStorageFilename = ".ppstorage" PPHiddenPathname = ".photoprism" )
const ( ExtJPEG = ".jpg" ExtPNG = ".png" ExtDNG = ".dng" ExtTHM = ".thm" ExtAVC = ".avc" ExtHEVC = ".hevc" ExtMP4 = ".mp4" ExtMOV = ".mov" ExtYAML = ".yml" )
const ( PathSeparator = string(filepath.Separator) Home = "~" HomePath = Home + PathSeparator )
const ( MimeTypeUnknown = "" MimeTypeBinary = "application/octet-stream" MimeTypeJPEG = "image/jpeg" MimeTypeJPEGXL = "image/jxl" MimeTypePNG = "image/png" MimeTypeAPNG = "image/vnd.mozilla.apng" MimeTypeGIF = "image/gif" MimeTypeBMP = "image/bmp" MimeTypeTIFF = "image/tiff" MimeTypeDNG = "image/dng" MimeTypeAVIF = "image/avif" MimeTypeAVIFS = "image/avif-sequence" MimeTypeHEIC = "image/heic" MimeTypeHEICS = "image/heic-sequence" MimeTypeWebP = "image/webp" MimeTypeMP4 = "video/mp4" MimeTypeMOV = "video/quicktime" MimeTypeSVG = "image/svg+xml" MimeTypeAI = "application/vnd.adobe.illustrator" MimeTypePS = "application/postscript" MimeTypeEPS = "image/eps" MimeTypeXML = "text/xml" MimeTypeJSON = "application/json" )
Variables ¶
var ( ModeDir os.FileMode = 0o777 ModeFile os.FileMode = 0o666 )
var AssetPaths = []string{
"/opt/photoprism/assets",
"/photoprism/assets",
"~/.photoprism/assets",
"~/photoprism/assets",
"photoprism/assets",
"assets",
"/var/lib/photoprism/assets",
}
var DscNameRegexp = regexp.MustCompile("\\D{3}[\\d_]\\d{4,8}_?\\d{0,6}_?\\d{0,6}[\\.jpgJPGXx]{0,4}")
var Extensions = FileExtensions{}/* 123 elements not displayed */
Extensions contains the filename extensions of file formats known to PhotoPrism.
var FileTypes = Extensions.Types(ignoreCase)
FileTypes contains the default file type extensions.
var ImportPaths = []string{
"/photoprism/storage/media/import",
"/photoprism/media/import",
"/photoprism/import",
"/srv/photoprism/storage/media/import",
"/srv/photoprism/media/import",
"/srv/photoprism/import",
"/opt/photoprism/storage/media/import",
"/opt/photoprism/media/import",
"/opt/photoprism/import",
"/media/import",
"/storage/import",
"/import",
"media/import",
"storage/import",
"photoprism/import",
"PhotoPrism/Import",
"pictures/import",
"Pictures/Import",
"photos/import",
"Photos/Import",
"import",
"Import",
"~/pictures/import",
"~/Pictures/Import",
"~/photoprism/import",
"~/PhotoPrism/Import",
"~/photos/import",
"~/Photos/Import",
"~/import",
"~/Import",
"/var/lib/photoprism/import",
}
var OriginalPaths = []string{
"/photoprism/storage/media/originals",
"/photoprism/media/originals",
"/photoprism/originals",
"/srv/photoprism/storage/media/originals",
"/srv/photoprism/media/originals",
"/srv/photoprism/originals",
"/opt/photoprism/storage/media/originals",
"/opt/photoprism/media/originals",
"/opt/photoprism/originals",
"/media/originals",
"/storage/originals",
"/originals",
"media/originals",
"storage/originals",
"photoprism/originals",
"PhotoPrism/Originals",
"photoprism/original",
"PhotoPrism/Original",
"pictures/originals",
"Pictures/Originals",
"pictures/original",
"Pictures/Original",
"photos/originals",
"Photos/Originals",
"photos/original",
"Photos/Original",
"originals",
"Originals",
"original",
"Original",
"pictures",
"Pictures",
"photos",
"Photos",
"images",
"Images",
"bilder",
"Bilder",
"fotos",
"Fotos",
"~/photoprism/originals",
"~/PhotoPrism/Originals",
"~/photoprism/original",
"~/PhotoPrism/Original",
"~/pictures/originals",
"~/Pictures/Originals",
"~/pictures/original",
"~/Pictures/Original",
"~/photos/originals",
"~/Photos/Originals",
"~/photos/original",
"~/Photos/Original",
"~/pictures",
"~/Pictures",
"~/photos",
"~/Photos",
"~/images",
"~/Images",
"~/bilder",
"~/Bilder",
"~/fotos",
"~/Fotos",
"/var/lib/photoprism/originals",
}
var TypeAnimated = TypeMap{ ImageGIF: MimeTypeGIF, ImagePNG: MimeTypeAPNG, ImageWebP: MimeTypeWebP, ImageAVIF: MimeTypeAVIFS, ImageAVIFS: MimeTypeAVIFS, ImageHEIC: MimeTypeHEICS, ImageHEICS: MimeTypeHEICS, }
TypeAnimated maps animated file types to their mime type.
var TypeInfo = TypeMap{
ImageRaw: "Unprocessed Sensor Data",
ImageDNG: "Adobe Digital Negative",
ImageJPEG: "Joint Photographic Experts Group (JPEG)",
ImageJPEGXL: "JPEG XL",
ImageThumb: "Thumbnail Image",
ImagePNG: "Portable Network Graphics",
ImageGIF: "Graphics Interchange Format",
ImageTIFF: "Tag Image File Format",
ImagePSD: "Adobe Photoshop",
ImageBMP: "Bitmap",
ImageMPO: "Stereoscopic JPEG (3D)",
ImageAVIF: "AV1 Image File Format",
ImageAVIFS: "AV1 Image Sequence",
ImageHEIF: "High Efficiency Image File Format",
ImageHEIC: "High Efficiency Image Container",
ImageHEICS: "HEIC Image Sequence",
ImageWebP: "Google WebP",
VideoWebM: "Google WebM",
VideoMP2: "MPEG 2 (H.262)",
VideoAVC: "Advanced Video Coding (H.264, MPEG-4 Part 10)",
VideoHEVC: "High Efficiency Video Coding (H.265)",
VideoVVC: "Versatile Video Coding (H.266)",
VideoAV1: "AOMedia Video 1",
VideoMOV: "Apple QuickTime",
VideoMP4: "Multimedia Container (MPEG-4 Part 14)",
VideoM4V: "Apple iTunes Multimedia Container",
VideoMXF: "Material Exchange Format",
VideoAVI: "Microsoft Audio Video Interleave",
VideoASF: "Advanced Systems Format ",
VideoWMV: "Windows Media",
VideoDV: "DV Video",
Video3GP: "Mobile Multimedia Container (3G)",
Video3G2: "Mobile Multimedia Container (CDMA2000)",
VideoFlash: "Adobe Flash",
VideoMKV: "Matroska Multimedia Container",
VideoMPG: "Moving Picture Experts Group (MPEG)",
VideoMJPG: "Motion JPEG",
VideoAVCHD: "Advanced Video Coding High Definition (AVCHD)",
VideoBDAV: "Blu-ray MPEG-2 Transport Stream",
VideoOGV: "Ogg Media (OGG)",
VectorSVG: "Scalable Vector Graphics",
VectorAI: "Adobe Illustrator",
VectorPS: "Adobe PostScript",
VectorEPS: "Encapsulated PostScript",
SidecarXMP: "Adobe Extensible Metadata Platform",
SidecarAAE: "Apple Image Edits XML",
SidecarXML: "Extensible Markup Language",
SidecarJSON: "Serialized JSON Data (Exiftool, Google Photos)",
SidecarYAML: "Serialized YAML Data (Config, Metadata)",
SidecarText: "Plain Text",
SidecarInfo: "Info Text",
SidecarMarkdown: "Markdown Formatted Text",
TypeUnknown: "Other",
}
TypeInfo contains human-readable descriptions for supported file formats
var UUIDNameRegexp = regexp.MustCompile("[A-Fa-f0-9\\-]{16,36}_?[A-Za-z0-9_]{0,20}") // Example: 8263987746_d0a6055c58_o
var UniqueNameRegexp = regexp.MustCompile("[a-f0-9]{8,16}_[a-f0-9]{6,16}_[A-Za-z0-9]{1,20}_?[A-Za-z0-9]{0,4}") // Example: 8263987746_d0a6055c58_o
Functions ¶
func BasePrefix ¶
BasePrefix returns the filename base without any extensions and path.
func CacheFileFromReader ¶
CacheFileFromReader writes data from an io.Reader to a file with the specified name if it does not exist. If the path does not exist or the file cannot be written, an error is returned. No error is returned if the file already exists.
func CachePath ¶
CachePath returns a cache directory name based on the base path, file hash and cache namespace.
func CanonicalName ¶
CanonicalName returns a canonical name based on time and CRC32 checksum.
func CaseInsensitive ¶
CaseInsensitive tests if a storage path is case-insensitive.
func DirIsEmpty ¶
DirIsEmpty returns true if a directory is empty.
func Dirs ¶
Dirs returns a slice of directories in a path, optional recursively and with symlinks.
Warning: Following symlinks can make the result non-deterministic and hard to test!
func FileExists ¶
FileExists returns true if file exists and is not a directory.
func FileExistsNotEmpty ¶
FileExistsNotEmpty returns true if file exists, is not a directory, and not empty.
func FileName ¶
FileName returns the relative filename with the same base and a given extension in a directory.
func FileNameHidden ¶
FileNameHidden tests is a file name belongs to a hidden file.
func FindDir ¶
FindDir checks if any of the specified directories exist and returns the absolute path of the first directory found.
func IsAnimatedImage ¶
IsAnimatedImage checks if the type associated with the specified filename may be animated.
func IsAsciiID ¶
IsAsciiID tests if the string is a file name that only contains uppercase ascii letters and numbers like "IQVG4929".
func IsCanonical ¶
IsCanonical returns true if the file basename is canonical.
func IsGenerated ¶
IsGenerated tests if the file name looks like an automatically generated identifier.
func IsUniqueName ¶
IsUniqueName tests if the string looks like a unique file name.
func MimeType ¶
MimeType returns the mime type of a file, or an empty string if it could not be detected.
func MkdirAll ¶
MkdirAll creates a directory including all parent directories that might not yet exist. No error is returned if the directory already exists.
func NonCanonical ¶
NonCanonical returns true if the file basename is NOT canonical.
func NormalizedExt ¶
NormalizedExt returns the file extension without dot and in lowercase.
func PathExists ¶
PathExists tests if a path exists, and is a directory or symlink.
func PathWritable ¶
PathWritable tests if a path exists and is writable.
func SkipWalk ¶
func SkipWalk(fileName string, isDir, isSymlink bool, done Done, ignore *IgnoreList) (skip bool, result error)
SkipWalk returns true if the file or directory should be skipped in godirwalk.Walk()
func StripKnownExt ¶
StripKnownExt removes all known file type extension from a file name (if any).
func StripSequence ¶
StripSequence removes common sequence patterns at the end of file names.
func SymlinksSupported ¶
SymlinksSupported tests if a storage path supports symlinks.
func TrimExt ¶
TrimExt removes unwanted characters from file extension strings, and makes it lowercase for comparison.
func WriteFile ¶
WriteFile overwrites a file with the specified bytes as content. If the path does not exist or the file cannot be written, an error is returned.
func WriteFileFromReader ¶
WriteFileFromReader writes data from an io.Reader to a newly created file with the specified name. If the path does not exist or the file cannot be written, an error is returned.
func WriteString ¶
WriteString overwrites a file with the specified string as content. If the path does not exist or the file cannot be written, an error is returned.
func WriteUnixTime ¶
WriteUnixTime overwrites a file with the current Unix timestamp as content. If the path does not exist or the file cannot be written, an error is returned.
Types ¶
type Blacklist ¶
Blacklist represents a file extension blacklist.
func NewBlacklist ¶
NewBlacklist creates and initializes a file extension blacklist.
type Blacklists ¶
Blacklists represents multiple blacklists.
func NewBlacklists ¶
func NewBlacklists() Blacklists
NewBlacklists creates and initializes file extension blacklists.
type FileExtensions ¶
FileExtensions maps file extensions to standard formats
func (FileExtensions) Known ¶
func (m FileExtensions) Known(name string) bool
Known tests if the file extension is known (supported).
func (FileExtensions) Types ¶
func (m FileExtensions) Types(noUppercase bool) TypesExt
Types returns known extensions by file type.
type FileInfo ¶
type FileInfo struct { Name string `json:"name"` Abs string `json:"abs"` Size int64 `json:"size"` Date time.Time `json:"date"` Dir bool `json:"dir"` }
FileInfo represents a file system entry.
func NewFileInfo ¶
NewFileInfo creates a FileInfo struct from the os.FileInfo record.
func WebFileInfo ¶
WebFileInfo creates a FileInfo struct from a webdav.FileInfo record.
type IgnoreItem ¶
IgnoreItem represents a file name pattern to be ignored.
func NewIgnoreItem ¶
func NewIgnoreItem(dir, pattern string, caseSensitive bool) IgnoreItem
NewIgnoreItem returns a pointer to a new IgnoreItem instance.
func (IgnoreItem) Ignore ¶
func (i IgnoreItem) Ignore(dir, base string) bool
Ignore returns true if the file name "base" in the directory "dir" should be ignored.
type IgnoreList ¶
type IgnoreList struct { Log IgnoreLogFunc // contains filtered or unexported fields }
IgnoreList represents a list of name patterns to be ignored.
func NewIgnoreList ¶
func NewIgnoreList(configFile string, ignoreHidden bool, caseSensitive bool) *IgnoreList
NewIgnoreList returns a pointer to a new IgnoreList instance.
func (*IgnoreList) AppendItems ¶
func (l *IgnoreList) AppendItems(dir string, patterns []string) error
AppendItems adds items to the list of ignored items.
func (*IgnoreList) ConfigFile ¶
func (l *IgnoreList) ConfigFile(fileName string) error
ConfigFile adds items in fileName to the list of ignored items.
func (*IgnoreList) Dir ¶
func (l *IgnoreList) Dir(dir string) error
Dir adds the ignore file in dirName to the list of ignored items.
func (*IgnoreList) Hidden ¶
func (l *IgnoreList) Hidden() []string
Hidden returns hidden files that were ignored.
func (*IgnoreList) Ignore ¶
func (l *IgnoreList) Ignore(fileName string) bool
Ignore returns true if the file name should be ignored.
func (*IgnoreList) Ignored ¶
func (l *IgnoreList) Ignored() []string
Ignored returns files that were ignored in addition to hidden files.
type IgnoreLogFunc ¶
type IgnoreLogFunc func(fileName string)
type Type ¶
type Type string
Type represents a file format type.
Supported media.Raw file types:
const ( ImageJPEG Type = "jpg" // JPEG Image ImageJPEGXL Type = "jxl" // JPEG XL Image ImageThumb Type = "thm" // Thumbnail Image ImagePNG Type = "png" // PNG Image ImageGIF Type = "gif" // GIF Image ImageTIFF Type = "tiff" // TIFF Image ImagePSD Type = "psd" // Adobe Photoshop ImageBMP Type = "bmp" // BMP Image ImageMPO Type = "mpo" // Stereoscopic Image that consists of two JPG images that are combined into one 3D image ImageAVIF Type = "avif" // AV1 Image File (AVIF) ImageAVIFS Type = "avifs" // AV1 Image Sequence (Animated AVIF) ImageHEIF Type = "heif" // High Efficiency Image File Format (HEIF) ImageHEIC Type = "heic" // High Efficiency Image Container (HEIC) ImageHEICS Type = "heics" // HEIC Image Sequence ImageWebP Type = "webp" // Google WebP Image )
Supported media.Image file types:
const ( VideoWebM Type = "webm" // Google WebM Video VideoHEVC Type = "hevc" // H.265, High Efficiency Video Coding (HEVC) VideoAVI Type = "avi" // Microsoft Audio Video Interleave (AVI) VideoAVC Type = "avc" // H.264, Advanced Video Coding (AVC, MPEG-4 Part 10) VideoVVC Type = "vvc" // H.266, Versatile Video Coding (VVC) VideoAV1 Type = "av1" // Alliance for Open Media Video VideoMPG Type = "mpg" // Moving Picture Experts Group (MPEG) VideoMJPG Type = "mjpg" // Motion JPEG (M-JPEG) VideoMP2 Type = "mp2" // MPEG-2, H.222/H.262 VideoMP4 Type = "mp4" // MPEG-4 Container based on QuickTime, can contain AVC, HEVC,... VideoM4V Type = "m4v" // Apple iTunes MPEG-4 Container, optionally with DRM copy protection VideoMKV Type = "mkv" // Matroska Multimedia Container, free and open VideoMOV Type = "mov" // QuickTime File Format, can contain AVC, HEVC,... VideoMXF Type = "mxf" // Material Exchange Format Video3GP Type = "3gp" // Mobile Multimedia Container, MPEG-4 Part 12 Video3G2 Type = "3g2" // Similar to 3GP, consumes less space & bandwidth VideoFlash Type = "flv" // Flash Video VideoAVCHD Type = "mts" // AVCHD (Advanced Video Coding High Definition) VideoBDAV Type = "m2ts" // Blu-ray MPEG-2 Transport Stream VideoOGV Type = "ogv" // Ogg container format maintained by the Xiph.Org, free and open VideoASF Type = "asf" // Advanced Systems/Streaming Format (ASF) VideoWMV Type = "wmv" // Windows Media Video (based on ASF) VideoDV Type = "dv" // DV Video (https://en.wikipedia.org/wiki/DV) )
Supported media.Video file types:
const ( VectorSVG Type = "svg" // Scalable Vector Graphics VectorAI Type = "ai" // Adobe Illustrator VectorPS Type = "ps" // Adobe PostScript VectorEPS Type = "eps" // Encapsulated PostScript )
Supported media.Vector file types:
const ( SidecarXMP Type = "xmp" // Adobe XMP sidecar file (XML) SidecarXML Type = "xml" // XML metadata / config / sidecar file SidecarAAE Type = "aae" // Apple image edits sidecar file (based on XML) SidecarYAML Type = "yml" // YAML metadata / config / sidecar file SidecarJSON Type = "json" // JSON metadata / config / sidecar file SidecarText Type = "txt" // Text config / sidecar file SidecarInfo Type = "nfo" // Info text file as used by e.g. Plex Media Server SidecarMarkdown Type = "md" // Markdown text sidecar file )
Supported media.Sidecar file types:
const TypeUnknown Type = ""
TypeUnknown is the default type used when a file cannot be classified.
func FileType ¶
FileType returns the type associated with the specified filename, and TypeUnknown if it could not be matched.
func (Type) DefaultExt ¶
DefaultExt returns the default file format extension with dot.
func (Type) FindAll ¶
func (t Type) FindAll(fileName string, dirs []string, baseDir string, stripSequence bool) (results []string)
FindAll searches a list of directories for files with the same base name and a given type.
func (Type) FindFirst ¶
FindFirst searches a list of directories for the first file with the same base name and a given type.
Source Files ¶
- blacklist.go
- cache.go
- canonical.go
- case.go
- codec.go
- const.go
- copy.go
- directories.go
- done.go
- file_ext.go
- file_exts.go
- file_info.go
- file_type.go
- file_type_animated.go
- file_types.go
- file_types_ext.go
- fileinfo.go
- filepath.go
- fs.go
- hash.go
- id.go
- ignore.go
- mime.go
- mode.go
- modtime.go
- move.go
- name.go
- readlines.go
- resolve.go
- symlink.go
- walk.go
- write.go
- zip.go