Skip to content

Commit

Permalink
fix error in init mode && Add unarchive logs
Browse files Browse the repository at this point in the history
Signed-off-by: Zemtsov Vladimir <[email protected]>
  • Loading branch information
zvlb committed Sep 24, 2022
1 parent c9e7b07 commit 870b781
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
### Added

### Release v0.0.4
- Fix: fix error in init mode
- Logging: Add unarchive logs

### Release v0.0.3
- Fix: Fix checks for webhook in initMode

### Release v0.0.2

- Cleanup: Add automatically tag image before push in Makefile
- Cleanup: Fix usage in ReadMe
- Cleanup: Fix error with CHANGELOG name file
Expand Down
12 changes: 7 additions & 5 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Run(cfg *config.Config) error {
}
if len(cfg.VolumeDirsArchive) > 0 {
for _, vda := range cfg.VolumeDirsArchive {
fmt.Printf("VDA: %s\n", vda)
unarchiveDir(vda, cfg)
}
if *cfg.InitMode {
Expand Down Expand Up @@ -103,7 +104,7 @@ func volumeDirArchiveWatcher(cfg *config.Config) error {
continue
}

err := unarchiveFile(event.Name, cfg)
err := unarchiveDir(event.Name, cfg)
if err != nil {
log.Println("Error:", err)
}
Expand Down Expand Up @@ -214,13 +215,15 @@ func sendWebHook(cfg *config.Config) {
}

func unarchiveDir(path string, cfg *config.Config) error {
files, err := ioutil.ReadDir(path)
kuberPath := path + "/..data"
files, err := ioutil.ReadDir(kuberPath)
if err != nil {
return err
}

for _, file := range files {
fullFilePath := path + "/" + file.Name()
fmt.Printf("file: %s", fullFilePath)
err := unarchiveFile(fullFilePath, cfg)
if err != nil {
return err
Expand All @@ -230,6 +233,8 @@ func unarchiveDir(path string, cfg *config.Config) error {
}

func unarchiveFile(path string, cfg *config.Config) error {
outFileName := *cfg.DirForUnarchive + "/" + filepath.Base(path)[0:len(filepath.Base(path))-3]
log.Printf("Unarhive file from %s to %s", path, outFileName)

if path[len(path)-3:] != ".gz" {
return fmt.Errorf("File %s is not a .gz archive. Do nothing", path)
Expand All @@ -247,9 +252,6 @@ func unarchiveFile(path string, cfg *config.Config) error {
defer gzipReader.Close()

// Uncompress to a writer. We'll use a file writer
outFileName := *cfg.DirForUnarchive + "/" + filepath.Base(path)[0:len(filepath.Base(path))-3]
// fmt.Println(outFileName)

outfileWriter, err := os.Create(outFileName)
if err != nil {
return err
Expand Down

0 comments on commit 870b781

Please sign in to comment.