-
Notifications
You must be signed in to change notification settings - Fork 0
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
53e13f0
commit fac23ed
Showing
6 changed files
with
81 additions
and
37 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
Empty file.
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
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,47 @@ | ||
package bitcaspy | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Exists returns true if the given path exists on the filesystem. | ||
func exists(path string) bool { | ||
if _, err := os.Stat(path); err != nil { | ||
return false | ||
} else { | ||
return true | ||
} | ||
} | ||
|
||
// returns the list of files in the database directory | ||
func getDatFiles(outDir string) ([]string, error) { | ||
if !exists(outDir) { | ||
return nil, fmt.Errorf("Error finding the file %s", outDir) | ||
} | ||
|
||
files, err := filepath.Glob(fmt.Sprintf("%s/*.db", outDir)) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error getting files from the directory %v", err) | ||
} | ||
return files, nil | ||
} | ||
|
||
// Returns the list of sorted ids of the file | ||
func getIds(files []string) ([]int, error) { | ||
ids := make([]int, 0) | ||
|
||
for _, file := range files { | ||
id, err := strconv.ParseInt((strings.TrimPrefix(strings.TrimSuffix(filepath.Base(file), ".db"), "bitcaspy_")), 10, 32) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error parsing the files path: %v", err) | ||
} | ||
ids = append(ids, int(id)) | ||
} | ||
sort.Ints(ids) | ||
return ids, nil | ||
} |