Source File
all.go
Belonging Package
github.com/hirochachacha/go-smb2
// Original: src/os/path.go
//
// Copyright 2009 The Go Authors. All rights reserved.
// Portions Copyright 2016 Hiroshi Ioka. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package smb2
import (
)
// MkdirAll mimics os.MkdirAll
func ( *Share) ( string, os.FileMode) error {
= normPath()
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
, := .Stat()
if == nil {
if .IsDir() {
return nil
}
return &os.PathError{Op: "mkdir", Path: , Err: syscall.ENOTDIR}
}
// Slow path: make sure parent exists and then call Mkdir for path.
:= len()
for > 0 && IsPathSeparator([-1]) { // Skip trailing path separator.
--
}
:=
for > 0 && !IsPathSeparator([-1]) { // Scan backward over element.
--
}
if > 1 {
// Create parent
= .([0:-1], )
if != nil {
return
}
}
// Parent now exists; invoke Mkdir and use its result.
= .Mkdir(, )
if != nil {
// Handle arguments like "foo/." by
// double-checking that directory doesn't exist.
, := .Lstat()
if == nil && .IsDir() {
return nil
}
return
}
return nil
}
// RemoveAll removes path and any children it contains.
// It removes everything it can but returns the first error
// it encounters. If the path does not exist, RemoveAll
// returns nil (no error).
func ( *Share) ( string) error {
= normPath()
// Simple case: if Remove works, we're done.
:= .Remove()
if == nil || os.IsNotExist() {
return nil
}
// Otherwise, is this a directory we need to recurse into?
, := .Lstat()
if != nil {
if , := .(*os.PathError); && (os.IsNotExist(.Err) || .Err == syscall.ENOTDIR) {
return nil
}
return
}
if !.IsDir() {
// Not a directory; return the error from Remove.
return
}
// Directory.
, := .Open()
if != nil {
if os.IsNotExist() {
// Race. It was deleted between the Lstat and Open.
// Return nil per RemoveAll's docs.
return nil
}
return
}
// Remove contents & return first error.
= nil
for {
, := .Readdirnames(100)
for , := range {
:= .( + string(PathSeparator) + )
if == nil {
=
}
}
if == io.EOF {
break
}
// If Readdirnames returned an error, use it.
if == nil {
=
}
if len() == 0 {
break
}
}
// Close directory, because windows won't remove opened directory.
.Close()
// Remove directory.
:= .Remove()
if == nil || os.IsNotExist() {
return nil
}
if == nil {
=
}
return
}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |