2024-01-01 10:31:45 +00:00
|
|
|
// Copyright (C) 2019 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
2023-01-03 09:18:30 +00:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2020-01-19 06:41:05 +00:00
|
|
|
package vfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-08-11 21:56:10 +00:00
|
|
|
"path"
|
2020-01-19 06:41:05 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-08-11 21:56:10 +00:00
|
|
|
// FileInfo implements os.FileInfo for a Cloud Storage file.
|
2020-01-31 18:04:00 +00:00
|
|
|
type FileInfo struct {
|
2020-01-19 06:41:05 +00:00
|
|
|
name string
|
|
|
|
sizeInBytes int64
|
|
|
|
modTime time.Time
|
|
|
|
mode os.FileMode
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:04:00 +00:00
|
|
|
// NewFileInfo creates file info.
|
2021-01-23 09:32:15 +00:00
|
|
|
func NewFileInfo(name string, isDirectory bool, sizeInBytes int64, modTime time.Time, fullName bool) *FileInfo {
|
2020-01-19 06:41:05 +00:00
|
|
|
mode := os.FileMode(0644)
|
|
|
|
if isDirectory {
|
|
|
|
mode = os.FileMode(0755) | os.ModeDir
|
|
|
|
}
|
2020-08-22 12:52:17 +00:00
|
|
|
if !fullName {
|
|
|
|
// we have always Unix style paths here
|
|
|
|
name = path.Base(name)
|
|
|
|
}
|
2020-01-19 06:41:05 +00:00
|
|
|
|
2021-01-23 09:32:15 +00:00
|
|
|
return &FileInfo{
|
2020-08-22 12:52:17 +00:00
|
|
|
name: name,
|
2020-01-19 06:41:05 +00:00
|
|
|
sizeInBytes: sizeInBytes,
|
|
|
|
modTime: modTime,
|
|
|
|
mode: mode,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name provides the base name of the file.
|
2021-01-23 09:32:15 +00:00
|
|
|
func (fi *FileInfo) Name() string {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Size provides the length in bytes for a file.
|
2021-01-23 09:32:15 +00:00
|
|
|
func (fi *FileInfo) Size() int64 {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.sizeInBytes
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mode provides the file mode bits
|
2021-01-23 09:32:15 +00:00
|
|
|
func (fi *FileInfo) Mode() os.FileMode {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.mode
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModTime provides the last modification time.
|
2021-01-23 09:32:15 +00:00
|
|
|
func (fi *FileInfo) ModTime() time.Time {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.modTime
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDir provides the abbreviation for Mode().IsDir()
|
2021-01-23 09:32:15 +00:00
|
|
|
func (fi *FileInfo) IsDir() bool {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.mode&os.ModeDir != 0
|
|
|
|
}
|
|
|
|
|
2021-01-23 09:32:15 +00:00
|
|
|
// SetMode sets the file mode
|
|
|
|
func (fi *FileInfo) SetMode(mode os.FileMode) {
|
|
|
|
fi.mode = mode
|
|
|
|
}
|
|
|
|
|
2020-01-19 06:41:05 +00:00
|
|
|
// Sys provides the underlying data source (can return nil)
|
2022-05-19 17:49:51 +00:00
|
|
|
func (fi *FileInfo) Sys() any {
|
2021-07-11 14:26:40 +00:00
|
|
|
return nil
|
2020-01-19 06:41:05 +00:00
|
|
|
}
|