This commit is contained in:
2026-01-29 18:44:51 +01:00
parent 10b142526b
commit 450d0185c9
2 changed files with 19 additions and 8 deletions
+9 -5
View File
@@ -11,6 +11,7 @@ type FileRepositoryInterface interface {
GetPath(path string) string
FileExists(path string) bool
CreateDir(path string) error
DeleteDir(path string) error
DeleteFile(path string) error
MoveFile(src_path, dest_path string) error
UnzipFile(path, dest_path string) error
@@ -42,6 +43,11 @@ func (fr *FileRepository) CreateDir(path string) error {
return os.MkdirAll(full_path, 0755)
}
func (fr *FileRepository) DeleteDir(path string) error {
full_path := fr.GetPath(path)
return os.RemoveAll(full_path)
}
func (fr *FileRepository) DeleteFile(path string) error {
full_path := fr.GetPath(path)
return os.RemoveAll(full_path)
@@ -60,14 +66,12 @@ func (fr *FileRepository) MoveFile(src_path, dest_path string) error {
}
func (fr *FileRepository) UnzipFile(path, destPath string) error {
fullPath := fr.GetPath(path)
fullDestPath := fr.GetPath(destPath)
if err := os.MkdirAll(fullDestPath, 0755); err != nil {
if err := os.MkdirAll(destPath, 0755); err != nil {
return err
}
cmd := exec.Command("unzip", "-q", fullPath, "-d", fullDestPath)
cmd := exec.Command("unzip", "-q", path, "-d", destPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@@ -75,5 +79,5 @@ func (fr *FileRepository) UnzipFile(path, destPath string) error {
return err
}
return os.Remove(fullPath)
return os.Remove(path)
}
+10 -3
View File
@@ -34,9 +34,16 @@ func (s *SoftwareUpdaterTIC80Service) Update(name, version string) error {
versioned_name := name + "-" + version
zip_path := s.fileRepository.GetPath(versioned_name + ".html.zip")
s.fileRepository.CreateDir(versioned_name)
s.fileRepository.UnzipFile(zip_path, versioned_name)
zip_filename := versioned_name + ".html.zip"
zip_path := s.fileRepository.GetPath(zip_filename)
zip_folder_path := s.fileRepository.GetPath(versioned_name)
if !s.fileRepository.FileExists(zip_folder_path) {
s.fileRepository.DeleteDir(zip_folder_path)
}
s.fileRepository.CreateDir(zip_folder_path)
s.fileRepository.UnzipFile(zip_path, zip_folder_path)
cartridge_path := s.fileRepository.GetPath(versioned_name + ".tic")
source_path := s.fileRepository.GetPath(versioned_name + ".lua")