From f4af5d2c21417f860a40862b1f33f4aae81689c5 Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Wed, 6 Sep 2023 16:20:05 +0800 Subject: [PATCH] pre --- lib/global/kits.go | 57 ++++++++++++++++++++++++++++++++++++++++++++ lib/routes/routes.go | 2 +- makefile | 1 + 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/global/kits.go b/lib/global/kits.go index baa71e5d..a32f9084 100644 --- a/lib/global/kits.go +++ b/lib/global/kits.go @@ -528,3 +528,60 @@ func ZipOneFile(srcFile, dstZip string, pathFlag bool) error { } return nil } + +func ZipDirectoryFile(srcDir, dstZip string, pathFlag bool) error { + // Create a new zip file + zipfileWriter, err := os.Create(dstZip) + if err != nil { + return err + } + defer zipfileWriter.Close() + + // Create a new zip archive + zipWriter := zip.NewWriter(zipfileWriter) + defer zipWriter.Close() + + // Walk through the directory and add files to the zip archive + err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + // Create a new file header for the current file + header, err := zip.FileInfoHeader(info) + if err != nil { + return err + } + + // Set the name of the file within the zip archive + header.Name = filepath.Join(filepath.Base(srcDir), path[len(srcDir):]) + + // If the current file is a directory, skip it + if info.IsDir() { + return nil + } + + // Create a new file in the zip archive + fileWriter, err := zipWriter.CreateHeader(header) + if err != nil { + return err + } + + // Open the current file + file, err := os.Open(path) + if err != nil { + return err + } + defer file.Close() + + // Copy the contents of the current file to the zip archive + _, err = io.Copy(fileWriter, file) + if err != nil { + return err + } + + return nil + }) + + return err +} diff --git a/lib/routes/routes.go b/lib/routes/routes.go index 2bcdb3e1..2c2d71ad 100644 --- a/lib/routes/routes.go +++ b/lib/routes/routes.go @@ -100,7 +100,7 @@ func init() { Register("PUT", dbrest.XormCommonUri, dbrest.DatabaseUpdateData, updatePermission) Register("DELETE", dbrest.XormCommonUri, dbrest.DatabaseDeleteData, deletePermission) - Register("GET", dbrest.XormDatabaseUri, dbrest.TaskDatabaseGetData, midware.CheckPermission) + Register("GET", dbrest.XormDatabaseUri, dbrest.TaskDatabaseGetData, selectPermission) Register("POST", dbrest.XormDatabaseUri, dbrest.TaskDatabaseInsertData, insertPermission) Register("PUT", dbrest.XormDatabaseUri, dbrest.TaskDatabaseUpdateData, updatePermission) Register("DELETE", dbrest.XormDatabaseUri, dbrest.TaskDatabaseDeleteData, deletePermission) diff --git a/makefile b/makefile index 39afbfd5..7e3f2682 100644 --- a/makefile +++ b/makefile @@ -91,6 +91,7 @@ deb: $(BINNAME) cp -rf $(EmsFEDir)/* $(FrontBuildDir)/front >/dev/null chmod 755 $(BinDir)/* chmod 755 $(BuildDir)/omc/bin/* + chmod 755 $(DebBuildDir)/DEBIAN/preinst chmod 755 $(DebBuildDir)/DEBIAN/postinst chmod 755 $(DebBuildDir)/DEBIAN/postrm cp -rf $(BuildDir)/omc/* $(DebBuildDir)/usr/local/omc/