Skip to content

Commit 66d8e9b

Browse files
committed
start reworking upload handler
1 parent 7d1e23a commit 66d8e9b

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

governor.go

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"errors"
5+
"log"
6+
"runtime/debug"
57
"sync"
68
)
79

@@ -34,6 +36,8 @@ func NewGovernor(max int) *Governor {
3436

3537
// ReadLock takes a read lock on this governor
3638
func (g *Governor) ReadLock() {
39+
log.Println("read loccked")
40+
debug.PrintStack()
3741
if g.Max != 0 {
3842
_ = <-g.reqs
3943
}
@@ -42,6 +46,8 @@ func (g *Governor) ReadLock() {
4246

4347
// ReadUnLock releases a read lock
4448
func (g *Governor) ReadUnLock() {
49+
log.Println("read unloccked")
50+
debug.PrintStack()
4551
g.rwLock.RUnlock()
4652
if g.Max != 0 {
4753
g.reqs <- req{}
@@ -51,6 +57,9 @@ func (g *Governor) ReadUnLock() {
5157
// WriteLock takes a write lock. THis shoudl block until all readers
5258
// are complete
5359
func (g *Governor) WriteLock() {
60+
log.Println("write loccked")
61+
debug.PrintStack()
62+
5463
if g.Max != 0 {
5564
for i := 0; i < g.Max; i++ {
5665
_ = <-g.reqs
@@ -61,6 +70,8 @@ func (g *Governor) WriteLock() {
6170

6271
// WriteUnLock releases the write lock
6372
func (g *Governor) WriteUnLock() (err error) {
73+
log.Println("write unloccked")
74+
debug.PrintStack()
6475
g.rwLock.Unlock()
6576
if g.Max != 0 {
6677
if len(g.reqs) != 0 {

server_cli.go

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func CmdServe(c *cli.Context) {
9696
r.Handle("/debug/vars", http.DefaultServeMux)
9797

9898
r.PathPrefix("/repo/").Handler(appHandler(makeHTTPDownloadHandler()))
99-
r.PathPrefix("/upload").Handler(appHandler(httpUploadHandler))
10099

101100
r.Handle("/dists", appHandler(httpDistsHandler))
102101
r.Handle("/dists/{name}", appHandler(httpDistsHandler))

upload_session.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ type UploadSession struct {
5353
// TODO revisit this
5454
incoming chan addItemMsg // New item upload requests
5555
getstatus chan getStatusMsg // A channel for responding to status requests
56-
geterr chan getStatusMsg // A channel for responding to status requests
5756
}
5857

5958
// ID returns the ID of this session
@@ -169,8 +168,7 @@ func (s *UploadSession) handler(ctx context.Context, cancel context.CancelFunc)
169168
}
170169
case msg := <-s.incoming:
171170
{
172-
if err := s.doAddFile(msg.file); err != nil {
173-
s.err = err
171+
if s.err = s.doAddFile(msg.file); s.err != nil {
174172
msg.resp <- *s
175173
break
176174
}
@@ -189,15 +187,8 @@ func (s *UploadSession) handler(ctx context.Context, cancel context.CancelFunc)
189187
s.Complete = true
190188
}
191189

192-
if err := s.usm.MergeSession(s); err != nil {
193-
log.Println(err)
194-
}
195-
196-
// cancel the context
197-
cancel()
198-
199-
// Need to do the update and return the response
200-
return
190+
s.usm.MergeSession(s)
191+
msg.resp <- *s
201192
}
202193
}
203194
}
@@ -402,7 +393,7 @@ func (s *UploadSession) doAddFile(upload *UploadFile) (err error) {
402393
// and placing it in the archive store.
403394
func (s *UploadSession) Err() error {
404395
c := make(chan UploadSession)
405-
s.geterr <- getStatusMsg{
396+
s.getstatus <- getStatusMsg{
406397
resp: c,
407398
}
408399
status := <-c

0 commit comments

Comments
 (0)