Fix readonly check for sidecar files #268 #348

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-06-07 14:33:07 +02:00
parent 1f9f52a95c
commit 793fd55712
5 changed files with 17 additions and 11 deletions

View file

@ -38,7 +38,7 @@ func StartIndexing(router *gin.RouterGroup, conf *config.Config) {
indOpt := photoprism.IndexOptions{
Rescan: f.Rescan,
Convert: f.Convert && (!conf.ReadOnly() || filepath.IsAbs(conf.SidecarPath())),
Convert: f.Convert && conf.SidecarWritable(),
Path: filepath.Clean(f.Path),
}

View file

@ -22,7 +22,7 @@ func convertAction(ctx *cli.Context) error {
conf := config.NewConfig(ctx)
service.SetConfig(conf)
if conf.ReadOnly() {
if !conf.SidecarWritable() {
return config.ErrReadOnly
}

View file

@ -65,7 +65,7 @@ func indexAction(ctx *cli.Context) error {
indOpt := photoprism.IndexOptions{
Path: subPath,
Rescan: ctx.Bool("all"),
Convert: conf.Settings().Index.Convert && (!conf.ReadOnly() || filepath.IsAbs(conf.SidecarPath())),
Convert: conf.Settings().Index.Convert && conf.SidecarWritable(),
}
indexed := ind.Start(indOpt)

View file

@ -178,7 +178,7 @@ func (c *Config) ExifToolBin() string {
// SidecarJson returns true if metadata should be synced with json sidecar files as used by exiftool.
func (c *Config) SidecarJson() bool {
if (c.ReadOnly() && !filepath.IsAbs(c.SidecarPath())) || c.ExifToolBin() == "" {
if !c.SidecarWritable() || c.ExifToolBin() == "" {
return false
}
@ -187,7 +187,7 @@ func (c *Config) SidecarJson() bool {
// SidecarYaml returns true if metadata should be synced with PhotoPrism YAML sidecar files.
func (c *Config) SidecarYaml() bool {
if c.ReadOnly() && !filepath.IsAbs(c.SidecarPath()) {
if !c.SidecarWritable() {
return false
}
@ -203,6 +203,16 @@ func (c *Config) SidecarPath() string {
return c.params.SidecarPath
}
// SidecarPathIsAbs returns true if sidecar path is absolute.
func (c *Config) SidecarPathIsAbs() bool {
return filepath.IsAbs(c.SidecarPath())
}
// SidecarWritable returns true if sidecar files can be created.
func (c *Config) SidecarWritable() bool {
return !c.ReadOnly() || c.SidecarPathIsAbs()
}
// HeifConvertBin returns the heif-convert executable file name.
func (c *Config) HeifConvertBin() string {
return findExecutable(c.params.HeifConvertBin, "heif-convert")

View file

@ -143,7 +143,7 @@ func (c *Convert) ToJson(mf *MediaFile) (*MediaFile, error) {
return result, nil
}
if c.conf.ReadOnly() {
if !c.conf.SidecarWritable() {
return nil, fmt.Errorf("convert: metadata export to json disabled in read only mode (%s)", mf.RelativeName(c.conf.OriginalsPath()))
}
@ -185,10 +185,6 @@ func (c *Convert) ToJson(mf *MediaFile) (*MediaFile, error) {
// ToJpeg converts a single image file to JPEG if possible.
func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) {
if c.conf.ReadOnly() {
return nil, errors.New("convert: disabled in read-only mode")
}
if !image.Exists() {
return nil, fmt.Errorf("convert: can not convert to jpeg, file does not exist (%s)", image.RelativeName(c.conf.OriginalsPath()))
}
@ -205,7 +201,7 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) {
return mediaFile, nil
}
if c.conf.ReadOnly() {
if !c.conf.SidecarWritable() {
return nil, fmt.Errorf("convert: disabled in read only mode (%s)", image.RelativeName(c.conf.OriginalsPath()))
}