Codebase list golang-github-unknwon-com / d1f167c
Import upstream version 2 Debian Janitor 2 years ago
4 changed file(s) with 77 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 # Compiled Object files, Static and Dynamic libs (Shared Objects)
1 *.o
2 *.a
3 *.so
4
5 # Folders
6 _obj
7 _test
8 .idea
9
10 # Architecture specific extensions/prefixes
11 *.[568vq]
12 [568vq].out
13
14 *.cgo1.go
15 *.cgo2.c
16 _cgo_defun.c
17 _cgo_gotypes.go
18 _cgo_export.*
19
20 _testmain.go
21
22 *.exe
23 *.iml
3131 return f.IsDir()
3232 }
3333
34 func statDir(dirPath, recPath string, includeDir, isDirOnly bool) ([]string, error) {
34 func statDir(dirPath, recPath string, includeDir, isDirOnly, followSymlinks bool) ([]string, error) {
3535 dir, err := os.Open(dirPath)
3636 if err != nil {
3737 return nil, err
5555 if includeDir {
5656 statList = append(statList, relPath+"/")
5757 }
58 s, err := statDir(curPath, relPath, includeDir, isDirOnly)
58 s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks)
5959 if err != nil {
6060 return nil, err
6161 }
6262 statList = append(statList, s...)
6363 } else if !isDirOnly {
6464 statList = append(statList, relPath)
65 } else if followSymlinks && fi.Mode()&os.ModeSymlink != 0 {
66 link, err := os.Readlink(curPath)
67 if err != nil {
68 return nil, err
69 }
70
71 if IsDir(link) {
72 if includeDir {
73 statList = append(statList, relPath+"/")
74 }
75 s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks)
76 if err != nil {
77 return nil, err
78 }
79 statList = append(statList, s...)
80 }
6581 }
6682 }
6783 return statList, nil
8399 if len(includeDir) >= 1 {
84100 isIncludeDir = includeDir[0]
85101 }
86 return statDir(rootPath, "", isIncludeDir, false)
102 return statDir(rootPath, "", isIncludeDir, false, false)
103 }
104
105 // LstatDir gathers information of given directory by depth-first.
106 // It returns slice of file list, follows symbolic links and includes subdirectories if enabled;
107 // it returns error and nil slice when error occurs in underlying functions,
108 // or given path is not a directory or does not exist.
109 //
110 // Slice does not include given path itself.
111 // If subdirectories is enabled, they will have suffix '/'.
112 func LstatDir(rootPath string, includeDir ...bool) ([]string, error) {
113 if !IsDir(rootPath) {
114 return nil, errors.New("not a directory or does not exist: " + rootPath)
115 }
116
117 isIncludeDir := false
118 if len(includeDir) >= 1 {
119 isIncludeDir = includeDir[0]
120 }
121 return statDir(rootPath, "", isIncludeDir, false, true)
87122 }
88123
89124 // GetAllSubDirs returns all subdirectories of given root path.
92127 if !IsDir(rootPath) {
93128 return nil, errors.New("not a directory or does not exist: " + rootPath)
94129 }
95 return statDir(rootPath, "", true, true)
130 return statDir(rootPath, "", true, true, false)
131 }
132
133 // LgetAllSubDirs returns all subdirectories of given root path, including
134 // following symbolic links, if any.
135 // Slice does not include given path itself.
136 func LgetAllSubDirs(rootPath string) ([]string, error) {
137 if !IsDir(rootPath) {
138 return nil, errors.New("not a directory or does not exist: " + rootPath)
139 }
140 return statDir(rootPath, "", true, true, true)
96141 }
97142
98143 // GetFileListBySuffix returns an ordered list of file paths.
1313
1414 package com
1515
16 // PowInt is int type of math.Pow function.
16 // PowInt is int type of math.Pow function.
1717 func PowInt(x int, y int) int {
1818 if y <= 0 {
1919 return 1
2020 } else {
21 if y % 2 == 0 {
21 if y%2 == 0 {
2222 sqrt := PowInt(x, y/2)
2323 return sqrt * sqrt
2424 } else {
1616 import (
1717 "testing"
1818
19 "bytes"
20 "crypto/rand"
1921 . "github.com/smartystreets/goconvey/convey"
20 "crypto/rand"
21 "bytes"
2222 )
2323
2424 func TestAESEncrypt(t *testing.T) {