From 450d0185c91f5d7802ae908b51bca58f4b7bc698 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Thu, 29 Jan 2026 18:44:51 +0100 Subject: [PATCH] zip fix --- domain/repository.file.go | 14 +++++++++----- domain/service.software_updater_tic80.go | 13 ++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/domain/repository.file.go b/domain/repository.file.go index 5fb1c75..c9a32d5 100644 --- a/domain/repository.file.go +++ b/domain/repository.file.go @@ -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) } diff --git a/domain/service.software_updater_tic80.go b/domain/service.software_updater_tic80.go index d8b6ae5..9aafa60 100644 --- a/domain/service.software_updater_tic80.go +++ b/domain/service.software_updater_tic80.go @@ -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")