"strconv"
"strings"
"sync"
+ "time"
"git.arvados.org/arvados.git/lib/cmd"
"git.arvados.org/arvados.git/lib/webdavfs"
Cache cache
Cluster *arvados.Cluster
setupOnce sync.Once
+
+ lockMtx sync.Mutex
+ lock map[string]*sync.RWMutex
+ lockTidied time.Time
}
var urlPDHDecoder = strings.NewReplacer(" ", "+", "-", "+")
// collection id is outside scope of supplied
// token
tokenScopeProblem = true
+ sess.Release()
continue
} else if os.IsNotExist(err) {
// collection does not exist or is not
// readable using this token
+ sess.Release()
continue
} else if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
+ sess.Release()
return
}
defer f.Close()
+ defer sess.Release()
collectionDir, sessionFS, session, tokenUser = f, fs, sess, user
break
}
h.logUploadOrDownload(r, session.arvadosclient, sessionFS, fsprefix+strings.Join(targetPath, "/"), nil, tokenUser)
- if writeMethod[r.Method] {
+ writing := writeMethod[r.Method]
+ locker := h.collectionLock(collectionID, writing)
+ defer locker.Unlock()
+
+ if writing {
// Save the collection only if/when all
// webdav->filesystem operations succeed --
// and send a 500 error if the modified
return nil, ""
}
+var lockTidyInterval = time.Minute * 10
+
+// Lock the specified collection for reading or writing. Caller must
+// call Unlock() on the returned Locker when the operation is
+// finished.
+func (h *handler) collectionLock(collectionID string, writing bool) sync.Locker {
+ h.lockMtx.Lock()
+ defer h.lockMtx.Unlock()
+ if time.Since(h.lockTidied) > lockTidyInterval {
+ // Periodically delete all locks that aren't in use.
+ h.lockTidied = time.Now()
+ for id, locker := range h.lock {
+ if locker.TryLock() {
+ locker.Unlock()
+ delete(h.lock, id)
+ }
+ }
+ }
+ locker := h.lock[collectionID]
+ if locker == nil {
+ locker = new(sync.RWMutex)
+ if h.lock == nil {
+ h.lock = map[string]*sync.RWMutex{}
+ }
+ h.lock[collectionID] = locker
+ }
+ if writing {
+ locker.Lock()
+ return locker
+ } else {
+ locker.RLock()
+ return locker.RLocker()
+ }
+}
+
func ServeCORSPreflight(w http.ResponseWriter, header http.Header) bool {
method := header.Get("Access-Control-Request-Method")
if method == "" {