-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add prompt and output when changing DA layer (#462)
- Loading branch information
1 parent
98504f4
commit 5e5b21c
Showing
11 changed files
with
138 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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,51 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func DirNotEmpty(path string) (bool, error) { | ||
info, err := os.Stat(path) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return false, nil | ||
} | ||
return false, err | ||
} | ||
|
||
if !info.IsDir() { | ||
return false, fmt.Errorf("%s is not a directory", path) | ||
} | ||
|
||
files, err := os.ReadDir(path) | ||
return len(files) > 0, err | ||
} | ||
|
||
func MoveFile(src, dst string) error { | ||
srcFile, err := os.Open(src) | ||
if err != nil { | ||
return fmt.Errorf("failed to open source file: %w", err) | ||
} | ||
defer func() { _ = srcFile.Close() }() | ||
err = os.MkdirAll(filepath.Dir(dst), 0755) | ||
if err != nil { | ||
return fmt.Errorf("failed to create parent directories: %w", err) | ||
} | ||
dstFile, err := os.Create(dst) | ||
if err != nil { | ||
return fmt.Errorf("failed to create destination file: %w", err) | ||
} | ||
defer func() { _ = dstFile.Close() }() | ||
_, err = io.Copy(dstFile, srcFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to copy file: %w", err) | ||
} | ||
err = os.Remove(src) | ||
if err != nil { | ||
return fmt.Errorf("failed to delete source file: %w", err) | ||
} | ||
return nil | ||
} |