zip refact
This commit is contained in:
@@ -65,13 +65,15 @@ func (fr *FileRepository) MoveFile(src_path, dest_path string) error {
|
||||
return os.Rename(full_src_path, full_dest_path)
|
||||
}
|
||||
|
||||
func (fr *FileRepository) UnzipFile(path, destPath string) error {
|
||||
func (fr *FileRepository) UnzipFile(zipfile, desc string) error {
|
||||
zip_path := fr.GetPath(zipfile)
|
||||
desc_path := fr.GetPath(desc)
|
||||
|
||||
if err := os.MkdirAll(destPath, 0755); err != nil {
|
||||
if err := os.MkdirAll(desc_path, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command("unzip", "-q", path, "-d", destPath)
|
||||
cmd := exec.Command("unzip", "-q", zip_path, "-d", desc_path)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
@@ -79,5 +81,5 @@ func (fr *FileRepository) UnzipFile(path, destPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.Remove(path)
|
||||
return os.Remove(zip_path)
|
||||
}
|
||||
|
||||
@@ -35,19 +35,20 @@ func (s *SoftwareUpdaterTIC80Service) Update(name, version string) error {
|
||||
versioned_name := name + "-" + version
|
||||
|
||||
zip_filename := versioned_name + ".html.zip"
|
||||
zip_path := s.fileRepository.GetPath(zip_filename)
|
||||
zip_folder_path := s.fileRepository.GetPath(versioned_name)
|
||||
cartridge_filename := versioned_name + ".tic"
|
||||
source_filename := versioned_name + ".lua"
|
||||
html_dirname := versioned_name
|
||||
|
||||
if !s.fileRepository.FileExists(zip_folder_path) {
|
||||
s.fileRepository.DeleteDir(zip_folder_path)
|
||||
if !s.fileRepository.FileExists(html_dirname) {
|
||||
s.fileRepository.DeleteDir(html_dirname)
|
||||
}
|
||||
|
||||
s.fileRepository.CreateDir(zip_folder_path)
|
||||
s.fileRepository.UnzipFile(zip_path, zip_folder_path)
|
||||
s.fileRepository.CreateDir(html_dirname)
|
||||
s.fileRepository.UnzipFile(zip_filename, html_dirname)
|
||||
|
||||
cartridge_path := s.fileRepository.GetPath(versioned_name + ".tic")
|
||||
source_path := s.fileRepository.GetPath(versioned_name + ".lua")
|
||||
html_folder_path := s.fileRepository.GetPath(versioned_name)
|
||||
cartridge_path := s.fileRepository.GetPath((cartridge_filename))
|
||||
source_path := s.fileRepository.GetPath(source_filename)
|
||||
html_dir_path := s.fileRepository.GetPath(html_dirname)
|
||||
|
||||
var err error
|
||||
|
||||
@@ -68,7 +69,7 @@ func (s *SoftwareUpdaterTIC80Service) Update(name, version string) error {
|
||||
Version: version,
|
||||
CartridgePath: cartridge_path,
|
||||
SourcePath: source_path,
|
||||
HTMLFolderPath: html_folder_path,
|
||||
HTMLFolderPath: html_dir_path,
|
||||
}
|
||||
|
||||
s.releaseRepository.CreateIfNotExist(&release)
|
||||
|
||||
Reference in New Issue
Block a user