Fix Remove for empty values on indexes

This commit is contained in:
Benedikt Kulmann
2020-10-16 09:44:39 +02:00
parent ae883908e5
commit 567ed1edbd
6 changed files with 18 additions and 0 deletions

View File

@@ -154,6 +154,9 @@ func (idx Autoincrement) Add(id, v string) (string, error) {
// Remove a value v from an index.
func (idx Autoincrement) Remove(id string, v string) error {
if v == "" {
return nil
}
searchPath := path.Join(idx.indexRootDir, v)
_, err := idx.resolveSymlink(searchPath)
if err != nil {

View File

@@ -169,6 +169,9 @@ func (idx *NonUnique) Add(id, v string) (string, error) {
// Remove a value v from an index.
func (idx *NonUnique) Remove(id string, v string) error {
if v == "" {
return nil
}
ctx, err := idx.getAuthenticatedContext(context.Background())
if err != nil {
return err

View File

@@ -155,6 +155,9 @@ func (idx *Unique) Add(id, v string) (string, error) {
// Remove a value v from an index.
func (idx *Unique) Remove(id string, v string) error {
if v == "" {
return nil
}
searchPath := path.Join(idx.indexRootDir, v)
_, err := idx.resolveSymlink(searchPath)
if err != nil {

View File

@@ -128,6 +128,9 @@ func (idx Autoincrement) Add(id, v string) (string, error) {
// Remove a value v from an index.
func (idx Autoincrement) Remove(id string, v string) error {
if v == "" {
return nil
}
searchPath := path.Join(idx.indexRootDir, v)
return os.Remove(searchPath)
}

View File

@@ -113,6 +113,9 @@ func (idx NonUniqueIndex) Add(id, v string) (string, error) {
// Remove a value v from an index.
func (idx NonUniqueIndex) Remove(id string, v string) error {
if v == "" {
return nil
}
res, err := filepath.Glob(path.Join(idx.indexRootDir, "/*/", id))
if err != nil {
return err

View File

@@ -93,6 +93,9 @@ func (idx Unique) Add(id, v string) (string, error) {
// Remove a value v from an index.
func (idx Unique) Remove(id string, v string) (err error) {
if v == "" {
return nil
}
searchPath := path.Join(idx.indexRootDir, v)
return os.Remove(searchPath)
}