Skip to content

Commit

Permalink
lib/os:MkdirAll use 1.21.13
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Aug 14, 2024
1 parent 8bd6e1d commit 997d673
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 117 deletions.
53 changes: 0 additions & 53 deletions internal/lib/internal/filepathlite/path.go

This file was deleted.

30 changes: 0 additions & 30 deletions internal/lib/internal/filepathlite/path_unix.go

This file was deleted.

17 changes: 0 additions & 17 deletions internal/lib/internal/stringslite/strings.go

This file was deleted.

26 changes: 9 additions & 17 deletions internal/lib/os/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package os

import (
"syscall"

"github.com/goplus/llgo/internal/lib/internal/filepathlite"
)

// MkdirAll creates a directory named path,
Expand All @@ -24,25 +22,19 @@ func MkdirAll(path string, perm FileMode) error {
}

// Slow path: make sure parent exists and then call Mkdir for path.

// Extract the parent folder from path by first removing any trailing
// path separator and then scanning backward until finding a path
// separator or reaching the beginning of the string.
i := len(path) - 1
for i >= 0 && IsPathSeparator(path[i]) {
i := len(path)
for i > 0 && IsPathSeparator(path[i-1]) { // Skip trailing path separator.
i--
}
for i >= 0 && !IsPathSeparator(path[i]) {
i--
}
if i < 0 {
i = 0

j := i
for j > 0 && !IsPathSeparator(path[j-1]) { // Scan backward over element.
j--
}

// If there is a parent directory, and it is not the volume name,
// recurse to ensure parent directory exists.
if parent := path[:i]; len(parent) > len(filepathlite.VolumeName(path)) {
err = MkdirAll(parent, perm)
if j > 1 {
// Create parent.
err = MkdirAll(fixRootDirectory(path[:j-1]), perm)
if err != nil {
return err
}
Expand Down

0 comments on commit 997d673

Please sign in to comment.