本文整理匯總了Golang中github.com/aclindsa/asink.Event.IsSameEvent方法的典型用法代碼示例。如果您正苦於以下問題:Golang Event.IsSameEvent方法的具體用法?Golang Event.IsSameEvent怎麽用?Golang Event.IsSameEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aclindsa/asink.Event
的用法示例。
在下文中一共展示了Event.IsSameEvent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ProcessRemoteEvent
func ProcessRemoteEvent(globals *AsinkGlobals, event *asink.Event) error {
var err error
StatStartRemoteUpdate()
defer StatStopRemoteUpdate()
latestLocal := LockPath(event.Path, false)
defer func() {
if err != nil {
event.LocalStatus |= asink.DISCARDED
}
UnlockPath(event)
}()
//get the absolute path because we may need it later
absolutePath := path.Join(globals.syncDir, event.Path)
//if we already have this event, or if it is older than our most recent event, bail out
if latestLocal != nil {
if event.Timestamp < latestLocal.Timestamp {
event.LocalStatus |= asink.DISCARDED
return nil
}
if event.IsSameEvent(latestLocal) {
return nil
}
if latestLocal.Hash != event.Predecessor && latestLocal.Hash != event.Hash {
err = handleConflict(globals, latestLocal, path.Join(globals.cacheDir, latestLocal.Hash))
if err != nil {
return ProcessingError{PERMANENT, err}
}
}
}
//Download event
if event.IsUpdate() {
if latestLocal == nil || event.Hash != latestLocal.Hash {
outfile, err := ioutil.TempFile(globals.tmpDir, "asink")
if err != nil {
return ProcessingError{CONFIG, err}
}
tmpfilename := outfile.Name()
StatStartDownload()
downloadReadCloser, err := globals.storage.Get(event.Hash)
if err != nil {
StatStopDownload()
return ProcessingError{STORAGE, err}
}
defer downloadReadCloser.Close()
if globals.encrypted {
decrypter, err := NewDecrypter(downloadReadCloser, globals.key)
if err != nil {
StatStopDownload()
return ProcessingError{STORAGE, err}
}
_, err = io.Copy(outfile, decrypter)
} else {
_, err = io.Copy(outfile, downloadReadCloser)
}
outfile.Close()
StatStopDownload()
if err != nil {
return ProcessingError{STORAGE, err}
}
//rename to local hashed filename
hashedFilename := path.Join(globals.cacheDir, event.Hash)
err = os.Rename(tmpfilename, hashedFilename)
if err != nil {
err = os.Remove(tmpfilename)
if err != nil {
return ProcessingError{PERMANENT, err}
}
return ProcessingError{PERMANENT, err}
}
//copy hashed file to another tmp, then rename it to the actual file.
tmpfilename, err = util.CopyToTmp(hashedFilename, globals.tmpDir)
if err != nil {
return ProcessingError{PERMANENT, err}
}
//make sure containing directory exists
err = util.EnsureDirExists(path.Dir(absolutePath))
if err != nil {
return ProcessingError{PERMANENT, err}
}
err = os.Rename(tmpfilename, absolutePath)
if err != nil {
err2 := os.Remove(tmpfilename)
if err2 != nil {
return ProcessingError{PERMANENT, err2}
}
return ProcessingError{PERMANENT, err}
}
}
if latestLocal == nil || event.Hash != latestLocal.Hash || event.Permissions != latestLocal.Permissions {
//.........這裏部分代碼省略.........