summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/afero
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/afero')
-rw-r--r--vendor/github.com/spf13/afero/const_bsds.go4
-rw-r--r--vendor/github.com/spf13/afero/const_win_unix.go4
-rw-r--r--vendor/github.com/spf13/afero/memmap.go65
3 files changed, 58 insertions, 15 deletions
diff --git a/vendor/github.com/spf13/afero/const_bsds.go b/vendor/github.com/spf13/afero/const_bsds.go
index eed0f225f..30855de57 100644
--- a/vendor/github.com/spf13/afero/const_bsds.go
+++ b/vendor/github.com/spf13/afero/const_bsds.go
@@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-//go:build aix || darwin || openbsd || freebsd || netbsd || dragonfly
-// +build aix darwin openbsd freebsd netbsd dragonfly
+//go:build aix || darwin || openbsd || freebsd || netbsd || dragonfly || zos
+// +build aix darwin openbsd freebsd netbsd dragonfly zos
package afero
diff --git a/vendor/github.com/spf13/afero/const_win_unix.go b/vendor/github.com/spf13/afero/const_win_unix.go
index 004d57e2f..12792d21e 100644
--- a/vendor/github.com/spf13/afero/const_win_unix.go
+++ b/vendor/github.com/spf13/afero/const_win_unix.go
@@ -10,8 +10,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-//go:build !darwin && !openbsd && !freebsd && !dragonfly && !netbsd && !aix
-// +build !darwin,!openbsd,!freebsd,!dragonfly,!netbsd,!aix
+//go:build !darwin && !openbsd && !freebsd && !dragonfly && !netbsd && !aix && !zos
+// +build !darwin,!openbsd,!freebsd,!dragonfly,!netbsd,!aix,!zos
package afero
diff --git a/vendor/github.com/spf13/afero/memmap.go b/vendor/github.com/spf13/afero/memmap.go
index e6b7d70b9..d6c744e8d 100644
--- a/vendor/github.com/spf13/afero/memmap.go
+++ b/vendor/github.com/spf13/afero/memmap.go
@@ -16,9 +16,12 @@ package afero
import (
"fmt"
"io"
+
"log"
"os"
"path/filepath"
+
+ "sort"
"strings"
"sync"
"time"
@@ -88,6 +91,24 @@ func (m *MemMapFs) findParent(f *mem.FileData) *mem.FileData {
return pfile
}
+func (m *MemMapFs) findDescendants(name string) []*mem.FileData {
+ fData := m.getData()
+ descendants := make([]*mem.FileData, 0, len(fData))
+ for p, dFile := range fData {
+ if strings.HasPrefix(p, name+FilePathSeparator) {
+ descendants = append(descendants, dFile)
+ }
+ }
+
+ sort.Slice(descendants, func(i, j int) bool {
+ cur := len(strings.Split(descendants[i].Name(), FilePathSeparator))
+ next := len(strings.Split(descendants[j].Name(), FilePathSeparator))
+ return cur < next
+ })
+
+ return descendants
+}
+
func (m *MemMapFs) registerWithParent(f *mem.FileData, perm os.FileMode) {
if f == nil {
return
@@ -309,29 +330,51 @@ func (m *MemMapFs) Rename(oldname, newname string) error {
if _, ok := m.getData()[oldname]; ok {
m.mu.RUnlock()
m.mu.Lock()
- m.unRegisterWithParent(oldname)
+ err := m.unRegisterWithParent(oldname)
+ if err != nil {
+ return err
+ }
+
fileData := m.getData()[oldname]
- delete(m.getData(), oldname)
mem.ChangeFileName(fileData, newname)
m.getData()[newname] = fileData
+
+ err = m.renameDescendants(oldname, newname)
+ if err != nil {
+ return err
+ }
+
+ delete(m.getData(), oldname)
+
m.registerWithParent(fileData, 0)
m.mu.Unlock()
m.mu.RLock()
} else {
return &os.PathError{Op: "rename", Path: oldname, Err: ErrFileNotFound}
}
+ return nil
+}
- for p, fileData := range m.getData() {
- if strings.HasPrefix(p, oldname+FilePathSeparator) {
- m.mu.RUnlock()
- m.mu.Lock()
- delete(m.getData(), p)
- p := strings.Replace(p, oldname, newname, 1)
- m.getData()[p] = fileData
- m.mu.Unlock()
- m.mu.RLock()
+func (m *MemMapFs) renameDescendants(oldname, newname string) error {
+ descendants := m.findDescendants(oldname)
+ removes := make([]string, 0, len(descendants))
+ for _, desc := range descendants {
+ descNewName := strings.Replace(desc.Name(), oldname, newname, 1)
+ err := m.unRegisterWithParent(desc.Name())
+ if err != nil {
+ return err
}
+
+ removes = append(removes, desc.Name())
+ mem.ChangeFileName(desc, descNewName)
+ m.getData()[descNewName] = desc
+
+ m.registerWithParent(desc, 0)
+ }
+ for _, r := range removes {
+ delete(m.getData(), r)
}
+
return nil
}