本文整理汇总了Golang中core.BuildTarget.OutMode方法的典型用法代码示例。如果您正苦于以下问题:Golang BuildTarget.OutMode方法的具体用法?Golang BuildTarget.OutMode怎么用?Golang BuildTarget.OutMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.BuildTarget
的用法示例。
在下文中一共展示了BuildTarget.OutMode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: moveOutput
func moveOutput(target *core.BuildTarget, tmpOutput, realOutput string, filegroup bool) (bool, error) {
// hash the file
newHash, err := pathHash(tmpOutput, false)
if err != nil {
return true, err
}
realOutputExists := core.PathExists(realOutput)
// If this is a filegroup we hardlink the outputs over and so the two files may actually be
// the same file. If so don't do anything else and especially don't delete & recreate the
// file because other things might be using it already (because more than one filegroup can
// own the same file).
if filegroup && realOutputExists && core.IsSameFile(tmpOutput, realOutput) {
movePathHash(tmpOutput, realOutput, filegroup) // make sure this is updated regardless
return false, nil
}
if realOutputExists {
if oldHash, err := pathHash(realOutput, false); err != nil {
return true, err
} else if bytes.Equal(oldHash, newHash) {
// We already have the same file in the current location. Don't bother moving it.
log.Debug("Checking %s vs. %s, hashes match", tmpOutput, realOutput)
return false, nil
}
if err := os.RemoveAll(realOutput); err != nil {
return true, err
}
}
movePathHash(tmpOutput, realOutput, filegroup)
// Check if we need a directory for this output.
dir := path.Dir(realOutput)
if !core.PathExists(dir) {
if err := os.MkdirAll(dir, core.DirPermissions); err != nil {
return true, err
}
}
// If the output file is in plz-out/tmp we can just move it to save time, otherwise we need
// to copy so we don't move files from other directories.
if strings.HasPrefix(tmpOutput, target.TmpDir()) {
if err := os.Rename(tmpOutput, realOutput); err != nil {
return true, err
}
} else {
if err := core.RecursiveCopyFile(tmpOutput, realOutput, target.OutMode(), filegroup, false); err != nil {
if filegroup && os.IsExist(err) && core.IsSameFile(tmpOutput, realOutput) {
// It's possible for two filegroups to race building simultaneously. In that
// case one will fail with an ErrExist, which is OK as far as we're concerned
// here as long as the file we tried to write really is the same as the input.
return true, nil
}
return true, err
}
}
if target.IsBinary {
if err := os.Chmod(realOutput, target.OutMode()); err != nil {
return true, err
}
}
return true, nil
}