支持Git提交导入及未提交源码叠加,APK原名下载和完成通知。新增服务端设备安装与按工程维护的私有文件清单,修复Wrapper预检查、布局及IDE读锁和保存状态问题。更新协议、测试和部署记录;服务端0.7.0,插件0.7.1。
94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package main
|
||
|
||
import (
|
||
"fmt"
|
||
"io"
|
||
"os"
|
||
"path/filepath"
|
||
"strings"
|
||
)
|
||
|
||
// 支持文件只接受管理员配置;不从源码同步或Git历史提取密钥。
|
||
func (s *Server) prepareWorkspaceFiles(p string, c BuildEnvironment) error {
|
||
pr := s.projects[p]
|
||
if !pr.Dedicated {
|
||
return nil
|
||
}
|
||
var configured map[string]string
|
||
for source, files := range c.WorkspaceFiles {
|
||
if sameAccessValue(filepath.Clean(source), pr.WorkspacePath) {
|
||
configured = files
|
||
break
|
||
}
|
||
}
|
||
names, err := s.privateNames(p)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
root := filepath.Join(s.root, "projects", p)
|
||
for relative, source := range configured {
|
||
for _, name := range names {
|
||
if sameAccessValue(relative, "work/"+name) && !sameAccessValue(source, filepath.Join(pr.WorkspacePath, filepath.FromSlash(name))) {
|
||
return fmt.Errorf("私有文件清单与已有workspaceFiles映射来源冲突:%s;请移除一处配置", name)
|
||
}
|
||
}
|
||
ext := strings.ToLower(filepath.Ext(relative))
|
||
base := filepath.Base(relative)
|
||
mapped := relative
|
||
switch ext {
|
||
case ".jks", ".keystore", ".cer":
|
||
mapped = strings.TrimSuffix(relative, filepath.Ext(relative)) + ".asset"
|
||
default:
|
||
if base != "local.properties" && base != "key.properties" && base != "keystore.properties" {
|
||
return fmt.Errorf("仅允许配置服务端签名/证书及本机属性支持文件:%s", relative)
|
||
}
|
||
mapped = filepath.ToSlash(filepath.Join(filepath.Dir(relative), "support.asset"))
|
||
}
|
||
if !validPath(mapped) || (strings.HasPrefix(relative, "work/") && ext == ".cer") {
|
||
return fmt.Errorf("非法支持文件目标:%s;证书应放在work的兄弟目录", relative)
|
||
}
|
||
if !filepath.IsAbs(source) {
|
||
return fmt.Errorf("支持文件来源必须为服务端绝对路径:%s", relative)
|
||
}
|
||
if e := noLinks(root); e != nil {
|
||
return e
|
||
}
|
||
dest := filepath.Join(root, filepath.FromSlash(relative))
|
||
if e := os.MkdirAll(filepath.Dir(dest), 0700); e != nil {
|
||
return e
|
||
}
|
||
input, e := os.Open(source)
|
||
if e != nil {
|
||
return fmt.Errorf("不能读取已配置的支持文件 %s:%w", relative, e)
|
||
}
|
||
info, e := input.Stat()
|
||
if e != nil || !info.Mode().IsRegular() || info.Size() > 16<<20 {
|
||
input.Close()
|
||
return fmt.Errorf("支持文件必须为小于16MiB的普通文件:%s", relative)
|
||
}
|
||
output, e := os.CreateTemp(filepath.Dir(dest), ".support-*")
|
||
if e != nil {
|
||
input.Close()
|
||
return e
|
||
}
|
||
name := output.Name()
|
||
written, copyErr := io.Copy(output, io.LimitReader(input, (16<<20)+1))
|
||
if copyErr == nil && written > 16<<20 {
|
||
copyErr = fmt.Errorf("支持文件过大:%s", relative)
|
||
}
|
||
input.Close()
|
||
closeErr := output.Close()
|
||
if copyErr == nil {
|
||
copyErr = closeErr
|
||
}
|
||
if copyErr == nil {
|
||
copyErr = os.Rename(name, dest)
|
||
}
|
||
os.Remove(name)
|
||
if copyErr != nil {
|
||
return copyErr
|
||
}
|
||
}
|
||
return s.preparePrivateFiles(p)
|
||
}
|