-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend/fs: fallback to file-based metadata when xattr isn't available
Related to #894.
- Loading branch information
Showing
6 changed files
with
84 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2022 Francisco Souza. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package backend | ||
|
||
type metadataHandler interface { | ||
write(path string, encoded []byte) error | ||
read(path string) ([]byte, error) | ||
remove(path string) error | ||
isSpecialFile(path string) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2022 Francisco Souza. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package backend | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
const metadataSuffix = ".metadata" | ||
|
||
type metadataFile struct{} | ||
|
||
func (m metadataFile) write(path string, encoded []byte) error { | ||
return os.WriteFile(path+metadataSuffix, encoded, 0o600) | ||
} | ||
|
||
func (m metadataFile) read(path string) ([]byte, error) { | ||
return os.ReadFile(path + metadataSuffix) | ||
} | ||
|
||
func (m metadataFile) isSpecialFile(path string) bool { | ||
return strings.HasSuffix(path, metadataSuffix) | ||
} | ||
|
||
func (m metadataFile) remove(path string) error { | ||
return os.Remove(path + metadataSuffix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2022 Francisco Souza. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package backend | ||
|
||
import ( | ||
"github.com/pkg/xattr" | ||
) | ||
|
||
const xattrKey = "user.metadata" | ||
|
||
type metadataXattr struct{} | ||
|
||
func (m metadataXattr) write(path string, encoded []byte) error { | ||
return xattr.Set(path, xattrKey, encoded) | ||
} | ||
|
||
func (m metadataXattr) read(path string) ([]byte, error) { | ||
return xattr.Get(path, xattrKey) | ||
} | ||
|
||
func (m metadataXattr) isSpecialFile(path string) bool { | ||
return false | ||
} | ||
|
||
func (m metadataXattr) remove(path string) error { | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.