Finish unfinished ProcessRemoteEvent functionality

This commit is contained in:
Aaron Lindsay 2013-08-13 23:17:45 -04:00
parent d5c199c021
commit fae1ed38d5

View File

@ -168,26 +168,44 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) {
} }
//Download event //Download event
if event.IsUpdate() && (latestLocal == nil || event.Hash != latestLocal.Hash) { if event.IsUpdate() {
outfile, err := ioutil.TempFile(globals.tmpDir, "asink") if latestLocal == nil || event.Hash != latestLocal.Hash {
if err != nil {
panic(err) //TODO handle sensibly
}
tmpfilename := outfile.Name()
outfile.Close()
err = globals.storage.Get(tmpfilename, event.Hash)
if err != nil {
panic(err) //TODO handle sensibly
}
//rename to local hashed filename outfile, err := ioutil.TempFile(globals.tmpDir, "asink")
err = os.Rename(tmpfilename, path.Join(globals.cacheDir, event.Hash)) if err != nil {
if err != nil { panic(err) //TODO handle sensibly
err := os.Remove(tmpfilename) }
tmpfilename := outfile.Name()
outfile.Close()
err = globals.storage.Get(tmpfilename, event.Hash)
if err != nil {
panic(err) //TODO handle sensibly
}
//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 {
panic(err)
}
panic(err)
}
//TODO copy hashed file to another tmp, then rename it to the actual file.
tmpfilename, err = util.CopyToTmp(hashedFilename, globals.tmpDir)
if err != nil { if err != nil {
panic(err) panic(err)
} }
panic(err) err = os.Rename(tmpfilename, event.Path)
if err != nil {
err := os.Remove(tmpfilename)
if err != nil {
panic(err)
}
panic(err)
}
} }
} else { } else {
//intentionally ignore errors in case this file has been deleted out from under us //intentionally ignore errors in case this file has been deleted out from under us