-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf83289
commit a670bf9
Showing
14 changed files
with
187 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package file | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func PutContentsMode(filename string, data string, mode os.FileMode) error { | ||
return ioutil.WriteFile(filename, []byte(data), mode) | ||
} | ||
|
||
func PutContents(filename string, data string) error { | ||
return ioutil.WriteFile(filename, []byte(data), 0751) | ||
} | ||
|
||
func GetContents(filename string) (string, error) { | ||
data, err := ioutil.ReadFile(filename) | ||
return string(data), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package file | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
func Copy(src, dst string) (int64, error) { | ||
src = FilterPath(src) | ||
dst = FilterPath(dst) | ||
|
||
//log.Println(src) | ||
//log.Println(dst) | ||
sourceFileStat, _err := os.Stat(src) | ||
if _err != nil { | ||
return 0, _err | ||
} | ||
|
||
if !sourceFileStat.Mode().IsRegular() { | ||
return 0, fmt.Errorf("%s is not a regular file", src) | ||
} | ||
|
||
source, _err := os.Open(src) | ||
if _err != nil { | ||
return 0, _err | ||
} | ||
defer source.Close() | ||
|
||
destination, _err := os.Create(dst) | ||
if _err != nil { | ||
return 0, _err | ||
} | ||
defer destination.Close() | ||
nBytes, _err := io.Copy(destination, source) | ||
return nBytes, _err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package file | ||
|
||
import "os" | ||
|
||
func RemoveAll(path string) error { | ||
return os.RemoveAll(path) | ||
} | ||
|
||
func RemoveRecursive(path string) error { | ||
return RemoveAll(path) | ||
} | ||
|
||
func DeleteAll(path string) error { | ||
return RemoveAll(path) | ||
} | ||
|
||
func DeleteRecursive(path string) error { | ||
return RemoveAll(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package file | ||
|
||
import "os" | ||
|
||
func Exists(filename string) bool { | ||
if _, err := os.Stat(filename); err == nil { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package file | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func getPathType(path string) uint8 { | ||
fi, err := os.Stat(path) | ||
if err != nil { | ||
fmt.Println(err) | ||
return 0 | ||
} | ||
switch mode := fi.Mode(); { | ||
case mode.IsDir(): | ||
// do directory stuff | ||
//fmt.Println("directory") | ||
return 1 | ||
case mode.IsRegular(): | ||
// do file stuff | ||
//fmt.Println("file") | ||
return 2 | ||
} | ||
return 0 | ||
} | ||
|
||
func IsFile(path string) bool { | ||
if getPathType(path) == 2 { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func IsDir(path string) bool { | ||
if getPathType(path) == 1 { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package file | ||
|
||
import ( | ||
"github.com/kyaxcorp/go-core/core/helpers/filesystem" | ||
"strings" | ||
) | ||
|
||
func FilterPath(path string) string { | ||
p := strings.ReplaceAll(path, `\\`, filesystem.DirSeparator()) | ||
p = strings.ReplaceAll(p, "//", filesystem.DirSeparator()) | ||
p = strings.ReplaceAll(p, "/", filesystem.DirSeparator()) | ||
p = strings.ReplaceAll(p, `\`, filesystem.DirSeparator()) | ||
return p | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package folder | ||
|
||
import "os" | ||
|
||
func Exists(path string) bool { | ||
if _, err := os.Stat(path); !os.IsNotExist(err) { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package folder | ||
|
||
import "os" | ||
|
||
func MkDir(path string) bool { | ||
/*err := os.Mkdir(path, 0751) | ||
if err != nil { | ||
log.Fatal(err) | ||
}*/ | ||
|
||
err := os.MkdirAll(path, 0751) | ||
if err != nil { | ||
//log.Fatal(err) | ||
return false | ||
} | ||
return true | ||
} |
Oops, something went wrong.