Skip to content

Commit

Permalink
add RemoveIn, bug permission file fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
verzth committed Apr 15, 2020
1 parent 6cc82d4 commit c0eadfc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 6 additions & 6 deletions utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"os"
)

func movePath(src string, dst string) {
func movePath(src string, dst string, perm os.FileMode) {
oFile, err := ioutil.ReadFile(src)
if err == nil {
os.MkdirAll(dst, os.ModeDir)
os.MkdirAll(dst, perm)
nFile, err := os.Create(dst)
if err != nil {
nFile.Write(oFile)
Expand All @@ -17,10 +17,10 @@ func movePath(src string, dst string) {
}
}

func moveFile(src string, dst string, filename string) {
moveFileRename(src,dst,filename,filename)
func moveFile(src string, dst string, filename string, perm os.FileMode) {
moveFileRename(src,dst,filename,filename, perm)
}

func moveFileRename(src string, dst string, filename string, newname string) {
movePath(src+filename, dst+newname)
func moveFileRename(src string, dst string, filename string, newname string, perm os.FileMode) {
movePath(src+filename, dst+newname, perm)
}
6 changes: 6 additions & 0 deletions utils/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (s slice) RemoveAt(collections interface{}, index int) {
}
}

func (s slice) RemoveIn(collections interface{}, indexes []int) {
for _, index := range indexes {
s.RemoveAt(collections, index)
}
}

// Uniquify(collections): Uniquify slices value
func (s slice) Uniquify(collections interface{}) {
indirect := reflect.ValueOf(collections)
Expand Down
10 changes: 6 additions & 4 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package utils

import "os"

func Substring(text string, indexs... int) string {
runes := []rune(text)
if len(indexs) > 0 {
Expand All @@ -20,13 +22,13 @@ func Substring(text string, indexs... int) string {
}
}

func FileMove(src string, dst string, file... string) {
func FileMove(src string, dst string, perm os.FileMode, file... string) {
pCount := len(file)
if pCount == 0 {
movePath(src,dst)
movePath(src,dst, perm)
}else if pCount == 1 {
moveFile(src,dst,file[0])
moveFile(src,dst,file[0],perm)
}else{
moveFileRename(src,dst,file[0],file[1])
moveFileRename(src,dst,file[0],file[1], perm)
}
}

0 comments on commit c0eadfc

Please sign in to comment.