func resourceBuildToDir(ImportPackageList []string, tmpDirPath string) (response resourceBuildToDirResponse) { builder := &tBuilder{ pkgMap: map[string]*pkg{}, } for _, importPath := range ImportPackageList { builder.handlePkg(importPath) } for _, pkg := range builder.pkgDepOrder { builder.JsContent = append(builder.JsContent, pkg.JsContent...) builder.JsContent = append(builder.JsContent, byte('\n')) builder.CssContent = append(builder.CssContent, pkg.CssContent...) builder.CssContent = append(builder.CssContent, byte('\n')) } response.CssFileName = kmgCrypto.Md5Hex(builder.CssContent) + ".css" response.JsFileName = kmgCrypto.Md5Hex(builder.JsContent) + ".js" kmgFile.MustMkdir(tmpDirPath) kmgFile.MustWriteFile(filepath.Join(tmpDirPath, response.CssFileName), builder.CssContent) kmgFile.MustWriteFile(filepath.Join(tmpDirPath, response.JsFileName), builder.JsContent) for _, pkg := range builder.pkgDepOrder { for _, filePath := range pkg.ResourceFilePathList { kmgFile.MustWriteFile(filepath.Join(tmpDirPath, filepath.Base(filePath)), kmgFile.MustReadFile(filePath)) } } for _, pkg := range builder.pkgDepOrder { response.NeedCachePathList = append(response.NeedCachePathList, pkg.Dirpath) } response.ImportPackageList = ImportPackageList return response }
func TestFileChangeCacheOneDir(t *testing.T) { callLog := make([]string, 32) //递归可用 kmgFile.MustDeleteFile(getFileChangeCachePath("test_file_change_cache")) kmgFile.MustMkdirAll("testFile/d1/d2") kmgFile.MustWriteFile("testFile/d1/d2/f3", []byte("1")) MustFileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[3] = "f3" }) kmgTest.Equal(callLog[3], "f3") MustFileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[4] = "f3" }) kmgTest.Equal(callLog[4], "") time.Sleep(time.Second * 1) kmgFile.MustWriteFile("testFile/d1/d2/f3", []byte("2")) MustFileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[5] = "f3" }) kmgTest.Equal(callLog[5], "f3") }
func TestMustMd5File(t *testing.T) { kmgFile.MustDelete("testFile") kmgFile.MustWriteFile("testFile", []byte("1")) md5name := MustMd5File("testFile") kmgTest.Equal(md5name, "c4ca4238a0b923820dcc509a6f75849b") kmgFile.MustWriteFile("testFile", []byte(md5name)) }
func TestMustIsFileInIndex(t *testing.T) { GitTestCb(func() { kmgCmd.MustRun("git init") kmgFile.MustWriteFile("1.txt", []byte("1")) kmgFile.MustWriteFile("2.txt", []byte("1")) kmgCmd.MustRun("git add 1.txt") repo := MustGetRepositoryFromPath(".") kmgTest.Equal(repo.MustIsFileInIndex("1.txt"), true) kmgTest.Equal(repo.MustIsFileInIndex("2.txt"), false) }) }
func TestMustIsFileIgnore(t *testing.T) { GitTestCb(func() { kmgCmd.MustRun("git init") kmgFile.MustWriteFile(".gitignore", []byte("/1.txt")) kmgFile.MustWriteFile("1.txt", []byte("1")) kmgFile.MustWriteFile("2.txt", []byte("1")) repo := MustGetRepositoryFromPath(".") kmgTest.Equal(repo.MustIsFileIgnore("1.txt"), true) kmgTest.Equal(repo.MustIsFileIgnore("notExist.txt"), false) kmgTest.Equal(repo.MustIsFileIgnore("2.txt"), false) }) }
func TestFileChangeCacheOneFile(t *testing.T) { //可以递归 遍历文件 //缓存数据文件不存在,没有问题 //指定的文件不存在,也没有问题 callLog := make([]string, 32) //指定的文件不存在 kmgFile.MustDeleteFile(getFileChangeCachePath("test_file_change_cache")) kmgFile.MustDeleteFile("testFile/notExist") MustFileChangeCache("test_file_change_cache", []string{ "testFile/notExist", }, func() { callLog[1] = "notExist" kmgFile.MustWriteFileWithMkdir("testFile/notExist", []byte("1")) }) kmgTest.Equal(callLog[1], "notExist") MustFileChangeCache("test_file_change_cache", []string{ "testFile/notExist", }, func() { callLog[2] = "notExist" }) kmgTest.Equal(callLog[2], "") time.Sleep(time.Second * 1) kmgFile.MustWriteFile("testFile/notExist", []byte("2")) MustFileChangeCache("test_file_change_cache", []string{ "testFile/notExist", }, func() { callLog[3] = "notExist" }) kmgTest.Equal(callLog[3], "notExist") }
func (command *GenerateHttpsCert) Execute(context *console.Context) (err error) { wd, err := os.Getwd() if err != nil { return } workDir := filepath.Join(wd, "certs") kmgFile.MustMkdirAll(workDir) os.Chdir(workDir) kmgFile.MustWriteFile("index.txt", []byte("")) kmgFile.MustWriteFile("serial", []byte("01")) kmgFile.MustWriteFile("config.conf", []byte(`[ ca ] default_ca = ca_default [ ca_default ] dir = . certs = . new_certs_dir = . database = ./index.txt serial = ./serial RANDFILE = .rand certificate = ca.crt private_key = ca.key default_days = 36500 default_crl_days = 30 default_md = md5 preserve = no policy = generic_policy [ policy_anything ] countryName = optional stateOrProvinceName = optional localityName = optional organizationName = optional organizationalUnitName = optional commonName = supplied emailAddress = optional`)) mustRunCmd("openssl req -passout pass:1234 -batch -new -x509 -newkey rsa:2048 -extensions v3_ca -keyout ca.key -out ca.crt -days 18250", "-subj", command.subject+" ca") mustRunCmd("openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out csr.csr -days 18250", "-subj", command.subject) mustRunCmdString("openssl ca -config config.conf -batch -cert ca.crt -passin pass:1234 -keyfile ca.key -policy policy_anything -out server.crt -infiles csr.csr") mustRunCmd("openssl req -new -newkey rsa:2048 -nodes -keyout client.key -out csr.csr -days 18250", "-subj", command.subject+" client") mustRunCmdString("openssl ca -config config.conf -batch -cert ca.crt -passin pass:1234 -keyfile ca.key -policy policy_anything -out client.crt -infiles csr.csr") mustRunCmdString("openssl pkcs12 -export -passout pass:1234 -inkey client.key -in client.crt -out client.pfx") return nil }
func cmd() { fmt.Println("children init finish") kmgConsole.WaitForExit() kmgFile.MustWriteFile("/tmp/2.log", []byte(time.Now().String())) fmt.Println("children after WaitForExit") time.Sleep(time.Second) fmt.Println("children after sleep") }
func MustWriteGolangVersion(versionFilePath string, version string) { kmgFile.MustWriteFile(versionFilePath, []byte(`package main import "github.com/bronze1man/kmg/kmgConsole" func init() { kmgConsole.VERSION = "`+version+`" } `)) }
func MustBuildTplInPathList(pathList []string) { for _, val := range pathList { ext := filepath.Ext(val) if ext == ".gotpl" { out, err := BuildTplOneFile(kmgFile.MustReadFile(val), false) if err != nil { panic(fmt.Sprintf("%s %s", val, err.Error())) } outFilePath := kmgFile.PathTrimExt(val) + ".go" kmgFile.MustWriteFile(outFilePath, out) } else if ext == ".gotplhtml" { out, err := BuildTplOneFile(kmgFile.MustReadFile(val), true) if err != nil { panic(fmt.Sprintf("%s %s", val, err.Error())) } outFilePath := kmgFile.PathTrimExt(val) + ".go" kmgFile.MustWriteFile(outFilePath, out) } } }
// 证实可用 func SetIpForwardOn() { if !kmgPlatform.IsLinux() { panic("[SetIpForwardOn] only support linux now") } kmgFile.MustWriteFile("/proc/sys/net/ipv4/ip_forward", []byte("1")) // 已经证实,多次写入不会出现任何问题. // TODO 正确解析/etc/sysctl.conf 如果后面又加一条 = 0 估计就挂了. if !bytes.Contains(kmgFile.MustReadFile("/etc/sysctl.conf"), []byte("\nnet.ipv4.ip_forward = 1")) { kmgFile.MustAppendFile("/etc/sysctl.conf", []byte("\nnet.ipv4.ip_forward = 1")) } }
func TestGitSubmoduleAddIgnore(ot *testing.T) { GitTestCb(func() { kmgCmd.MustRun("git init") kmgFile.MustWriteFile(".gitignore", []byte("/subIgnored")) kmgFile.MustWriteFileWithMkdir("subIgnored/1.txt", []byte("1")) kmgCmd.CmdString("git init").SetDir("subIgnored").MustRun() kmgCmd.CmdString("git add -A").SetDir("subIgnored").MustRun() kmgCmd.CmdString("git commit -am'save'").SetDir("subIgnored").MustRun() repo := MustGetRepositoryFromPath(".") repo.MustFakeSubmoduleAdd("subIgnored") kmgTest.Equal(repo.MustIsFileInIndex("subIgnored"), false) }) }
func SshCertCopyCertToRemote(cert string, remoteList []RemoteServer) { kmgFile.MustWriteFile("/tmp/cert", []byte(cert)) defer kmgFile.MustDelete("/tmp/cert") for _, remote := range remoteList { cmd := []string{"ssh", "-t", "-p", strconv.Itoa(remote.SshPort), remote.UserName + "@" + remote.Address} kmgCmd.CmdSlice([]string{"scp", "-P", strconv.Itoa(remote.SshPort), "/tmp/cert", remote.UserName + "@" + remote.Address + ":~/"}).MustRun() authorizedKeysByte := kmgCmd.CmdSlice(append(cmd, "cat ~/.ssh/authorized_keys")).MustRunAndReturnOutput() if strings.Contains(string(authorizedKeysByte), cert) { fmt.Println("Cert has contains in authorized_keys") continue } kmgCmd.CmdSlice(append(cmd, "mkdir .ssh;cat cert >> .ssh/authorized_keys;rm cert")).MustRun() } }
func MustBuildTplInDir(path string) { pathList, err := kmgFile.GetAllFiles(path) if err != nil { panic(err) } for _, val := range pathList { if filepath.Ext(val) != ".jst" { continue } out := MustBuildTplOneFile(kmgFile.MustReadFile(val)) outFilePath := kmgFile.PathTrimExt(val) + ".js" kmgFile.MustWriteFile(outFilePath, out) } }
func ResourceBuild(req *ResourceUploadRequest) { if req.Name == "" { panic(`[ResourceBuild] req.Name == ""`) } tmpDirPath := kmgConfig.DefaultEnv().PathInTmp("kmgViewResource_build/" + req.Name) kmgFile.MustDelete(tmpDirPath) response := resourceBuildToDir(req.ImportPathList, tmpDirPath) req.Qiniu.MustUploadFromFile(tmpDirPath, req.QiniuPrefix) packageName := filepath.Base(filepath.Dir(req.OutGoFilePath)) urlPrefix := req.Qiniu.GetSchemeAndDomain() + "/" + req.QiniuPrefix //jsUrl:=urlPrefix+"/"+response.JsFileName //cssUrl:=urlPrefix+"/"+response.CssFileName // 不可以使用 fmt.Sprintf("%#v",generated) 会导出私有变量. //generated:=&Generated{ // Name: req.Name, // GeneratedJsFileUrl: jsUrl, // GeneratedCssFileUrl: cssUrl, // GeneratedUrlPrefix: urlPrefix, // RequestImportList: req.ImportPathList, //} outGoContent := []byte(`package ` + packageName + ` import ( "github.com/bronze1man/kmg/kmgView/kmgViewResource" "sync" ) var ` + req.Name + `Once sync.Once var ` + req.Name + `generated *kmgViewResource.Generated func get` + req.Name + `ViewResource() *kmgViewResource.Generated{ ` + req.Name + `Once.Do(func(){ ` + req.Name + `generated = &kmgViewResource.Generated{ Name: ` + fmt.Sprintf("%#v", req.Name) + `, GeneratedJsFileName: ` + fmt.Sprintf("%#v", response.JsFileName) + `, GeneratedCssFileName: ` + fmt.Sprintf("%#v", response.CssFileName) + `, GeneratedUrlPrefix: ` + fmt.Sprintf("%#v", urlPrefix) + `, RequestImportList: ` + fmt.Sprintf("%#v", req.ImportPathList) + `, } ` + req.Name + `generated.Init() }) return ` + req.Name + `generated } `) outGoContent, err := kmgFormat.Source(outGoContent) if err != nil { panic(err) } kmgFile.MustWriteFile(req.OutGoFilePath, outGoContent) }
func selfUpdate() { prefixB, err := kmgHttp.UrlGetContent("http://kmgtools.qiniudn.com/v1/kmgUrlPrefix.txt?v=" + kmgRand.MustCryptoRandToAlphaNum(16)) kmgConsole.ExitOnErr(err) exeContent, err := kmgHttp.UrlGetContent(string(prefixB) + "_windows_amd64.exe") kmgConsole.ExitOnErr(err) //cmd 这个东西有超级神力,直接os.Rename不行 但是360会报警 // 已经试过下列方案: // 1.os.Rename 后面的write会没有权限,原因不明 // 2.move windows上面没有这个命令 kmgCmd.ProxyRun(`cmd /c move C:\windows\system32\kmg.exe C:\windows\system32\kmg-old.exe`) kmgFile.MustWriteFile(`C:\windows\system32\kmg.exe`, exeContent) }
func installGolangWithUrlMap(urlMap map[string]string) { p := kmgPlatform.GetCompiledPlatform() if p.Compatible(kmgPlatform.WindowsAmd64) { contentB, err := kmgHttp.UrlGetContent(urlMap["windows_amd64"]) kmgConsole.ExitOnErr(err) kmgFile.MustDelete(`c:\go`) err = kmgCompress.ZipUncompressFromBytesToDir(contentB, `c:\go`, "go") kmgConsole.ExitOnErr(err) err = kmgFile.CopyFile(`c:\go\bin\go.exe`, `c:\windows\system32\go.exe`) kmgConsole.ExitOnErr(err) err = kmgFile.CopyFile(`c:\go\bin\godoc.exe`, `c:\windows\system32\godoc.exe`) kmgConsole.ExitOnErr(err) err = kmgFile.CopyFile(`c:\go\bin\gofmt.exe`, `c:\windows\system32\gofmt.exe`) kmgConsole.ExitOnErr(err) return } tmpPath := kmgFile.MustChangeToTmpPath() defer kmgFile.MustDelete(tmpPath) if !kmgSys.MustIsRoot() { fmt.Println("you need to be root to install golang") return } url, ok := urlMap[p.String()] if !ok { kmgConsole.ExitOnErr(fmt.Errorf("not support platform [%s]", p)) } packageName := path.Base(url) contentB := kmgHttp.MustUrlGetContentProcess(url) kmgFile.MustWriteFile(packageName, contentB) kmgCmd.ProxyRun("tar -xf " + packageName) if kmgFile.MustFileExist("/usr/local/go") { kmgCmd.ProxyRun("mv /usr/local/go /usr/local/go.bak." + time.Now().Format(kmgTime.FormatFileNameV2)) } kmgCmd.ProxyRun("cp -rf go /usr/local") kmgFile.MustDeleteFile("/bin/go") kmgCmd.ProxyRun("ln -s /usr/local/go/bin/go /bin/go") kmgFile.MustDeleteFile("/bin/godoc") kmgCmd.ProxyRun("ln -s /usr/local/go/bin/godoc /bin/godoc") kmgFile.MustDeleteFile("/bin/gofmt") kmgCmd.ProxyRun("ln -s /usr/local/go/bin/gofmt /bin/gofmt") kmgFile.MustEnsureBinPath("/bin/go") kmgFile.MustEnsureBinPath("/bin/godoc") kmgFile.MustEnsureBinPath("/bin/gofmt") }
func runCommand(kmgc *kmgConfig.Env, args []string) { os.Chdir(kmgc.ProjectPath) logDir := filepath.Join(kmgc.LogPath, "run") kmgFile.MustMkdirAll(logDir) thisLogFilePath := filepath.Join(logDir, time.Now().Format(kmgTime.FormatFileName)+".log") kmgFile.MustWriteFile(thisLogFilePath, []byte{}) if !kmgPlatform.GetCompiledPlatform().Compatible(kmgPlatform.WindowsAmd64) { lastLogPath := filepath.Join(logDir, "last.log") if kmgFile.MustFileExist(lastLogPath) { kmgFile.MustSymlink(kmgFile.MustReadSymbolLink(lastLogPath), filepath.Join(logDir, "last2.log")) } kmgFile.MustSymlink(filepath.Base(thisLogFilePath), lastLogPath) } //TODO 大部分命令是 kmg gorun xxx 在这个地方可以直接调用gorun解决问题,这样可以少开一个进程加快了一些速度 // 问题: 上述做法不靠谱,会导致last.log没有用处. //if len(args) >= 2 && args[0] == "kmg" && strings.EqualFold(args[1], "gorun") { // os.Args = append(args[1:], os.Args[1:]...) // goCmd.GoRunCmd() // return //} // 下面的做法不靠谱,会让signle无法传递 //err := kmgCmd.CmdSlice(append(args, os.Args[1:]...)). // SetDir(kmgc.ProjectPath). // RunAndTeeOutputToFile(thisLogFilePath) // TODO bash转义 bashCmd := strings.Join(append(args, os.Args[1:]...), " ") bashCmdStr := bashCmd + " 2>&1 | tee -i " + thisLogFilePath + " ; test ${PIPESTATUS[0]} -eq 0" if kmgPlatform.IsWindows() { err := kmgCmd.CmdString(bashCmdStr).SetDir(kmgc.ProjectPath).StdioRun() if err != nil { err = fmt.Errorf("kmg make: %s", err) kmgConsole.ExitOnErr(err) } return } else { err := kmgCmd.CmdBash(bashCmdStr).SetDir(kmgc.ProjectPath).StdioRun() if err != nil { err = fmt.Errorf("kmg make: %s", err) kmgConsole.ExitOnErr(err) } return } }
func main() { kmgCmd.MustRun(`kmg GoCrossCompile -platform linux_amd64 github.com/bronze1man/kmg/kmg`) kmgCmd.MustRun(`kmg GoCrossCompile -platform linux_amd64 github.com/bronze1man/kmg/kmg/SubCommand/serviceCmd/testBin`) kmgFile.MustCopyFile(filepath.Join(kmgConfig.DefaultEnv().ProjectPath, "bin/kmg_linux_amd64"), filepath.Join(dockerPath, "kmg")) kmgFile.MustCopyFile(filepath.Join(kmgConfig.DefaultEnv().ProjectPath, "bin/testBin_linux_amd64"), filepath.Join(dockerPath, "testBin")) kmgFile.MustWriteFile(filepath.Join(dockerPath, "Dockerfile"), []byte(`FROM ubuntu WORKDIR / COPY kmg /bin/ COPY testBin /bin/ RUN chmod +x /bin/kmg RUN chmod +x /bin/testBin CMD testBin `)) //CMD kmg service setandrestart t testBin && kmg service stop t && kmg service start t && kmg service restart t kmgCmd.MustRunAndReturnOutput("docker build -t kmgtest " + dockerPath) for i := 0; i < 20; i++ { time.Sleep(time.Second) kmgCmd.MustRunAndReturnOutput("docker run kmgtest") } }
func TestGitFixNameCaseWithFile(ot *testing.T) { oldWd, err := os.Getwd() kmgTest.Equal(err, nil) kmgFile.MustDelete("testfile") kmgFile.Mkdir("testfile") os.Chdir("testfile") defer os.Chdir(oldWd) kmgFile.MustWriteFile("a.txt", []byte("abc")) kmgCmd.MustRun("git init") kmgCmd.MustRun("git add -A") kmgCmd.MustRun("git commit -am'save'") err = os.Rename("a.txt", "A.txt") kmgTest.Equal(err, nil) err = GitFixNameCase(filepath.Join(oldWd, "testfile")) kmgTest.Equal(err, nil) kmgCmd.MustRun("git status") kmgCmd.MustRun("git add -A") kmgCmd.MustRun("git commit -am'save'") }
func TestGoRunFile(ot *testing.T) { wd, err := os.Getwd() if err != nil { panic(err) } defer os.Chdir(wd) root := kmgConfig.DefaultEnv().ProjectPath os.Chdir(root) kmgPath := filepath.Join(root, "bin/kmg") kmgFile.MustDelete(kmgPath) //kmgCmd.MustRun("kmg go install github.com/bronze1man/kmg/kmg") gopath := filepath.Join(wd, "testWorkspace") os.Chdir(gopath) kmgFile.MustDelete(filepath.Join(gopath, "bin")) kmgFile.MustDelete(filepath.Join(gopath, "pkg")) kmgFile.MustDelete(filepath.Join(gopath, "tmp")) kmgFile.MustDelete(filepath.Join(gopath, "src", "kmgTestMain", "other.go")) goRunInstall(gopath, "kmgTestMain") output := kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "kmgTestMain")) kmgTest.Equal(string(output), "1\n") kmgFile.MustWriteFile(filepath.Join(wd, "testWorkspace", "src", "kmgTestMain", "other.go"), []byte(` package main func init(){ a=2 } `)) goRunInstall(gopath, "kmgTestMain") output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "kmgTestMain")) kmgTest.Equal(string(output), "2\n") kmgFile.MustDelete(filepath.Join(wd, "testWorkspace", "src", "kmgTestMain", "other.go")) goRunInstall(gopath, "kmgTestMain") output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "kmgTestMain")) kmgTest.Equal(string(output), "1\n") goRunInstall(gopath, "kmgTestMain/l2Main") output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "l2Main")) kmgTest.Equal(string(output), "l2Main\n") kmgFile.MustWriteFile(filepath.Join(gopath, "src", "replaceBin", "replaceBin.go"), []byte(` package main import "fmt" func main(){ fmt.Println("replaceBin") } `)) goRunInstall(gopath, "replaceBin") output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "replaceBin")) kmgTest.Equal(string(output), "replaceBin\n") kmgFile.MustWriteFile(filepath.Join(gopath, "src", "replaceBin", "replaceBin.go"), []byte(` package replaceBin var A = "1" `)) goRunInstall(gopath, "replaceBin") // 应该会说这个不是main的package }
func TestFileMd5ChangeCacheOneDir(t *testing.T) { callLog := make([]string, 32) //递归可用 kmgFile.MustDeleteFile(getFileChangeCachePath("test_file_change_cache")) kmgFile.MustDelete("testFile/d1") kmgFile.MustMkdirAll("testFile/d1/d2") kmgFile.MustWriteFile("testFile/d1/d2/f3", []byte("1")) MustMd5FileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[3] = "f3" }) kmgTest.Equal(callLog[3], "f3") //没有碰过任何东西,缓存有效 MustMd5FileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[4] = "f3" }) kmgTest.Equal(callLog[4], "") //修改文件内容,缓存应该无效 kmgFile.MustWriteFile("testFile/d1/d2/f3", []byte("2")) MustMd5FileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[5] = "f3" }) kmgTest.Equal(callLog[5], "f3") //删除文件,缓存应该无效 kmgFile.MustDelete("testFile/d1/d2/f3") MustMd5FileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[6] = "f4" }) kmgTest.Equal(callLog[6], "f4") //添加文件,缓存应该无效 kmgFile.MustWriteFile("testFile/d1/d2/f4", []byte("3")) MustMd5FileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[7] = "f4" }) kmgTest.Equal(callLog[7], "f4") //读取文件,缓存有效 kmgFile.MustReadFile("testFile/d1/d2/f4") MustMd5FileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[8] = "f4" }) kmgTest.Equal(callLog[8], "") //创建目录,缓存有效 kmgFile.MustMkdir("testFile/d1/d2/f5") MustMd5FileChangeCache("test_file_change_cache", []string{ "testFile/d1", }, func() { callLog[9] = "f4" }) kmgTest.Equal(callLog[9], "") }
func (fm *FileMutex) ownAndLock() { kmgFile.MustWriteFile(fm.filePath, []byte("1")) fm.isOwner = true }