This commit is contained in:
Arnas Udovicius 2022-05-08 23:19:55 +03:00
parent fdbbc02d0a
commit 2d1ac09ba1

24
tree.go
View file

@ -33,12 +33,13 @@ func BuildTree(dirPath string, meta []string) (Tree, error) {
}
func PopulateTree(sourcePath string, destPath string, meta []string) error {
err = fixFormat(sourcePath)
err := fixFormat(sourcePath)
if err != nil {
return err
}
id, err := getMaxId(sourcePath)
var id int64 = 0
id, err = getMaxId(sourcePath)
if err != nil {
return err
}
@ -87,9 +88,9 @@ func fixFormat(dir string) error {
format = false
}
if (format) {
if format {
line = strings.Trim(line, " ")
if (line != "") {
if line != "" {
content = content + "\n" + line
}
} else {
@ -314,20 +315,20 @@ func readFile(file fs.FileInfo, fullPath string, category []string, meta []strin
}
for _, option := range meta {
if strings.HasPrefix(line, option) {
line = strings.TrimPrefix(line, option + ":")
line = strings.TrimPrefix(line, option+":")
f.Meta[option] = strings.Trim(line, " ")
}
}
}
osf.Close()
_ = osf.Close()
return f, nil
}
func ReadFileContent(file File) (string, error) {
osf, err := os.Open(path)
osf, err := os.Open(file.FullPath)
if err != nil {
return nil, err
return "", err
}
content := ""
@ -342,13 +343,13 @@ func ReadFileContent(file File) (string, error) {
continue
}
if (isMetaPart) {
if isMetaPart {
continue
}
if (removeEmptyLine) {
if removeEmptyLine {
line = strings.Trim(line, " ")
if (line == "") {
if line == "" {
continue
} else {
removeEmptyLine = false
@ -357,6 +358,7 @@ func ReadFileContent(file File) (string, error) {
content = content + "\n" + line
}
_ = osf.Close()
return content, nil
}