handle directory listing edge cases

This commit is contained in:
Chris Lu 2020-12-21 23:37:43 -08:00
parent c74bede730
commit fe46411cd4
2 changed files with 18 additions and 7 deletions

View file

@ -30,12 +30,23 @@ func NewFilerStorePathTranlator(storeRoot string, store FilerStore) *FilerStoreP
} }
} }
func (t *FilerStorePathTranlator) translatePath(fp util.FullPath) (newPath util.FullPath){
newPath = fp
if t.storeRoot == "/" {
return
}
newPath = fp[len(t.storeRoot)-1:]
if newPath == "" {
newPath = "/"
}
return
}
func (t *FilerStorePathTranlator) changeEntryPath(entry *Entry) (previousPath util.FullPath){ func (t *FilerStorePathTranlator) changeEntryPath(entry *Entry) (previousPath util.FullPath){
previousPath = entry.FullPath previousPath = entry.FullPath
if t.storeRoot == "/" { if t.storeRoot == "/" {
return return
} }
entry.FullPath = previousPath[len(t.storeRoot)-1:] entry.FullPath = t.translatePath(previousPath)
return return
} }
func (t *FilerStorePathTranlator) recoverEntryPath(entry *Entry, previousPath util.FullPath) { func (t *FilerStorePathTranlator) recoverEntryPath(entry *Entry, previousPath util.FullPath) {
@ -68,7 +79,7 @@ func (t *FilerStorePathTranlator) FindEntry(ctx context.Context, fp util.FullPat
if t.storeRoot == "/" { if t.storeRoot == "/" {
return t.actualStore.FindEntry(ctx, fp) return t.actualStore.FindEntry(ctx, fp)
} }
newFullPath := fp[len(t.storeRoot)-1:] newFullPath := t.translatePath(fp)
entry, err = t.actualStore.FindEntry(ctx, newFullPath) entry, err = t.actualStore.FindEntry(ctx, newFullPath)
if err == nil { if err == nil {
entry.FullPath = fp[:len(t.storeRoot)-1] + entry.FullPath entry.FullPath = fp[:len(t.storeRoot)-1] + entry.FullPath
@ -77,7 +88,7 @@ func (t *FilerStorePathTranlator) FindEntry(ctx context.Context, fp util.FullPat
} }
func (t *FilerStorePathTranlator) DeleteEntry(ctx context.Context, fp util.FullPath) (err error) { func (t *FilerStorePathTranlator) DeleteEntry(ctx context.Context, fp util.FullPath) (err error) {
newFullPath := fp[len(t.storeRoot)-1:] newFullPath := t.translatePath(fp)
return t.actualStore.DeleteEntry(ctx, newFullPath) return t.actualStore.DeleteEntry(ctx, newFullPath)
} }
@ -90,14 +101,14 @@ func (t *FilerStorePathTranlator) DeleteOneEntry(ctx context.Context, existingEn
} }
func (t *FilerStorePathTranlator) DeleteFolderChildren(ctx context.Context, fp util.FullPath) (err error) { func (t *FilerStorePathTranlator) DeleteFolderChildren(ctx context.Context, fp util.FullPath) (err error) {
newFullPath := fp[len(t.storeRoot)-1:] newFullPath := t.translatePath(fp)
return t.actualStore.DeleteFolderChildren(ctx, newFullPath) return t.actualStore.DeleteFolderChildren(ctx, newFullPath)
} }
func (t *FilerStorePathTranlator) ListDirectoryEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int) ([]*Entry, error) { func (t *FilerStorePathTranlator) ListDirectoryEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int) ([]*Entry, error) {
newFullPath := dirPath[len(t.storeRoot)-1:] newFullPath := t.translatePath(dirPath)
entries, err := t.actualStore.ListDirectoryEntries(ctx, newFullPath, startFileName, includeStartFile, limit) entries, err := t.actualStore.ListDirectoryEntries(ctx, newFullPath, startFileName, includeStartFile, limit)
if err != nil { if err != nil {
@ -111,7 +122,7 @@ func (t *FilerStorePathTranlator) ListDirectoryEntries(ctx context.Context, dirP
func (t *FilerStorePathTranlator) ListDirectoryPrefixedEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int, prefix string) ([]*Entry, error) { func (t *FilerStorePathTranlator) ListDirectoryPrefixedEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int, prefix string) ([]*Entry, error) {
newFullPath := dirPath[len(t.storeRoot)-1:] newFullPath := t.translatePath(dirPath)
entries, err := t.actualStore.ListDirectoryPrefixedEntries(ctx, newFullPath, startFileName, includeStartFile, limit, prefix) entries, err := t.actualStore.ListDirectoryPrefixedEntries(ctx, newFullPath, startFileName, includeStartFile, limit, prefix)
if err != nil { if err != nil {

View file

@ -237,7 +237,7 @@ func (fsw *FilerStoreWrapper) ListDirectoryPrefixedEntries(ctx context.Context,
} }
func (fsw *FilerStoreWrapper) prefixFilterEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int, prefix string) (entries []*Entry, err error) { func (fsw *FilerStoreWrapper) prefixFilterEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int, prefix string) (entries []*Entry, err error) {
actualStore := fsw.getActualStore(dirPath) actualStore := fsw.getActualStore(dirPath+"/")
entries, err = actualStore.ListDirectoryEntries(ctx, dirPath, startFileName, includeStartFile, limit) entries, err = actualStore.ListDirectoryEntries(ctx, dirPath, startFileName, includeStartFile, limit)
if err != nil { if err != nil {
return nil, err return nil, err