func (c *client) uploadDirectory(serverUrl, localPath, remotePath, dirFileFilterPattern string) (returnErr error) { defer CatchPanicAsError(&returnErr) c.simpleLogger.Debug("Now starting to upload local directory '%s' to remote '%s", localPath, remotePath) checkResponseFunc := c.checkServerResponse walkContext := ziputils.NewDirWalkContext(dirFileFilterPattern) ziputils.UploadDirectoryToUrl(c.simpleLogger, serverUrl+"?dir="+url.QueryEscape(remotePath), "application/octet-stream", localPath, walkContext, checkResponseFunc) return nil }
func (a *appContext) handler(w http.ResponseWriter, r *http.Request) { defer a.recoveryFunc(w, r, "ERROR in handler: %+v") if r.Method == "POST" { path, isDir := a.getFileOrFolderFromRequest(r) if isDir { a.logger.Info("Receiving directory (zipped) %s", path) ziputils.SaveTarReaderToPath(a.logger, r.Body, path) } else { a.logger.Info("Receiving file to %s", path) ziputils.SaveTarReaderToPath(a.logger, r.Body, path) } } else if r.Method == "GET" { path := a.getPathFromRequest(r) if a.isDir(path) { a.logger.Info("Sending directory %s", path) walkContext := ziputils.NewDirWalkContext(a.getDirFileFilterPatternFromRequest(r)) ziputils.UploadDirectoryToHttpResponseWriter(a.logger, w, path, walkContext) } else { a.logger.Info("Sending file %s", path) ziputils.UploadFileToHttpResponseWriter(a.logger, w, path) } } else if r.Method == "DELETE" { path := a.getPathFromRequest(r) if a.isDir(path) { a.logger.Info("Deleting directory %s", path) walkContext := ziputils.NewDirWalkContext(a.getDirFileFilterPatternFromRequest(r)) walkContext.DeleteDirectory(path) } else { a.logger.Info("Deleting file %s", path) err := os.Remove(path) CheckError(err) } } else if r.Method == "PUT" { action := a.getRequiredQueryValue(r, "action") switch strings.ToLower(action) { case "move": oldPath := a.getPathFromRequest(r) newPath := a.getRequiredQueryValue(r, "newpath") err := os.Rename(oldPath, newPath) CheckError(err) break default: panic("Unsupported action '" + action + "'") } } else if r.Method == "HEAD" { path := a.getPathFromRequest(r) a.logger.Info("Sending stats for path %s", path) info, err := os.Stat(path) if os.IsNotExist(err) { w.Header().Set("EXISTS", "0") return } CheckError(err) w.Header().Set("EXISTS", "1") if info.IsDir() { w.Header().Set("IS_DIR", "1") } else { w.Header().Set("IS_DIR", "0") } } else { panic("Unsupported method " + r.Method) } }