Automatically create/delete directories around file creation/removal

This commit is contained in:
2013-08-14 22:59:40 -04:00
parent ccb35fc7a6
commit 6f72225b5b
2 changed files with 26 additions and 3 deletions

View File

@ -236,6 +236,13 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) {
if err != nil {
panic(err)
}
//make sure containing directory exists
err = util.EnsureDirExists(path.Dir(absolutePath))
if err != nil {
panic(err)
}
err = os.Rename(tmpfilename, absolutePath)
if err != nil {
err2 := os.Remove(tmpfilename)
@ -254,7 +261,8 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) {
} else {
//intentionally ignore errors in case this file has been deleted out from under us
os.Remove(absolutePath)
//TODO delete file hierarchy beneath this file if its the last one in its directory?
//delete the directory previously containing this file if its the last file
util.RecursiveRemoveEmptyDirs(path.Dir(absolutePath))
}
//TODO make sure file being overwritten is either unchanged or already copied off and hashed