심볼링크 로그 파일은 빼고 삭제
This commit is contained in:
@ -15,6 +15,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -77,7 +78,7 @@ func (hc *houstonClient) uploadZipLogFile(zipFile string, name string, version s
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except string) (string, []string, error) {
|
func zipLogFiles(storageRoot string, req *shared.UploadRequest) (string, []string, error) {
|
||||||
root := path.Join(storageRoot, req.Name, req.Version)
|
root := path.Join(storageRoot, req.Name, req.Version)
|
||||||
matches, err := filepath.Glob(path.Join(root, req.Filter))
|
matches, err := filepath.Glob(path.Join(root, req.Filter))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -95,6 +96,7 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except st
|
|||||||
|
|
||||||
root = path.Join(root, path.Dir(req.Filter))
|
root = path.Join(root, path.Dir(req.Filter))
|
||||||
zipFileName := path.Join(os.TempDir(), path.Base(matches[0])) + ".zip"
|
zipFileName := path.Join(os.TempDir(), path.Base(matches[0])) + ".zip"
|
||||||
|
os.Remove(zipFileName)
|
||||||
f, err := os.OpenFile(zipFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
|
f, err := os.OpenFile(zipFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -110,13 +112,14 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except st
|
|||||||
if file == root {
|
if file == root {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(except) > 0 && file >= except {
|
|
||||||
matches = matches[:i]
|
if fi, err := os.Lstat(file); err == nil {
|
||||||
break
|
if (fi.Mode() & os.ModeSymlink) == os.ModeSymlink {
|
||||||
}
|
matches[i] = ""
|
||||||
if len(start) > 0 && file < start {
|
continue
|
||||||
continue
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(oldestFile) == 0 {
|
if len(oldestFile) == 0 {
|
||||||
oldestFile = path.Base(file)
|
oldestFile = path.Base(file)
|
||||||
}
|
}
|
||||||
@ -124,19 +127,16 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except st
|
|||||||
relative := file[len(root)+1:]
|
relative := file[len(root)+1:]
|
||||||
fw, err := w.Create(relative)
|
fw, err := w.Create(relative)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
src, err := os.Open(file)
|
src, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
defer src.Close()
|
defer src.Close()
|
||||||
|
|
||||||
if _, err = io.Copy(fw, src); err != nil {
|
if _, err = io.Copy(fw, src); err != nil {
|
||||||
logger.Println(err)
|
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -496,12 +496,15 @@ func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
|
|||||||
logger.Println("uploadFiles found :", child.version, child.name)
|
logger.Println("uploadFiles found :", child.version, child.name)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req, "", "")
|
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req)
|
||||||
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
||||||
if err = hc.uploadZipLogFile(zipFile, child.name, child.version); err == nil {
|
if err = hc.uploadZipLogFile(zipFile, child.name, child.version); err == nil {
|
||||||
// 마지막거 빼고 삭제
|
// 마지막거 빼고 삭제
|
||||||
|
sort.StringSlice(srcFiles).Sort()
|
||||||
for i := 0; i < len(srcFiles)-1; i++ {
|
for i := 0; i < len(srcFiles)-1; i++ {
|
||||||
os.Remove(srcFiles[i])
|
if len(srcFiles[i]) > 0 {
|
||||||
|
os.Remove(srcFiles[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Println("uploadZipLogFile failed :", err)
|
logger.Println("uploadZipLogFile failed :", err)
|
||||||
@ -517,9 +520,17 @@ func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
|
|||||||
|
|
||||||
// 실행 중이 아닌 폴더에서도 대상을 찾는다
|
// 실행 중이 아닌 폴더에서도 대상을 찾는다
|
||||||
// 전체 파일을 대상으로
|
// 전체 파일을 대상으로
|
||||||
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req, "", "")
|
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req)
|
||||||
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
||||||
if err = hc.uploadZipLogFile(zipFile, req.Name, req.Version); err != nil {
|
if err = hc.uploadZipLogFile(zipFile, req.Name, req.Version); err == nil {
|
||||||
|
// 마지막거 빼고 삭제
|
||||||
|
sort.StringSlice(srcFiles).Sort()
|
||||||
|
for i := 0; i < len(srcFiles)-1; i++ {
|
||||||
|
if len(srcFiles[i]) > 0 {
|
||||||
|
os.Remove(srcFiles[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
logger.Println("uploadZipLogFile failed :", err)
|
logger.Println("uploadZipLogFile failed :", err)
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user