Test Failed
Push — master ( afbf8e...641184 )
by Valentin
02:35
created

util.PathsEqual   A

Complexity

Conditions 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nop 2
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
1
package util
2
3
import (
4
	"encoding/csv"
5
	"log"
6
	"os"
7
	"path/filepath"
8
	"strings"
9
)
10
11
func MustOpenReadonlyFile(filename string) *os.File {
1 ignored issue
show
introduced by
exported function MustOpenReadonlyFile should have comment or be unexported
Loading history...
12
	file, err := os.OpenFile(filename, os.O_RDONLY, os.ModePerm)
13
	if err != nil {
14
		log.Fatalln(err)
15
	}
16
17
	return file
18
}
19
20
func GetCSVReader(file *os.File, sep rune) *csv.Reader {
1 ignored issue
show
introduced by
exported function GetCSVReader should have comment or be unexported
Loading history...
21
	reader := csv.NewReader(file)
22
	reader.Comma = sep
23
	reader.FieldsPerRecord = -1
24
25
	return reader
26
}
27
28
func FileExists(filename string) bool {
1 ignored issue
show
introduced by
exported function FileExists should have comment or be unexported
Loading history...
29
	_, err := os.Stat(filename)
30
31
	return err == nil
32
}
33
34
func Extension(filename string) string {
1 ignored issue
show
introduced by
exported function Extension should have comment or be unexported
Loading history...
35
	return strings.Trim(filepath.Ext(filename), ".")
36
}
37
38
func Abs(path string) string {
1 ignored issue
show
introduced by
exported function Abs should have comment or be unexported
Loading history...
39
	abs, err := filepath.Abs(path)
40
	if err == nil {
41
		return abs
42
	}
43
44
	return path
45
}
46
47
func PathsEqual(p1, p2 string) bool {
1 ignored issue
show
introduced by
exported function PathsEqual should have comment or be unexported
Loading history...
48
	p1 = strings.TrimRight(p1, "/\\")
49
	p2 = strings.TrimRight(p2, "/\\")
50
51
	if p1 == p2 {
52
		return true
53
	}
54
55
	if filepath.FromSlash(p1) == filepath.FromSlash(p2) {
56
		return true
57
	}
58
59
	if filepath.ToSlash(p1) == filepath.ToSlash(p2) {
60
		return true
61
	}
62
63
	return false
64
}
65