New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce download-store & 2 steps download #256
Conversation
Codecov Report@@ Coverage Diff @@
## master #256 +/- ##
==========================================
+ Coverage 74.21% 74.26% +0.04%
==========================================
Files 69 70 +1
Lines 5345 5468 +123
==========================================
+ Hits 3967 4061 +94
- Misses 934 952 +18
- Partials 444 455 +11
Continue to review full report at Codecov.
|
docs/files.md
Outdated
@@ -592,7 +592,7 @@ Location: http://cozy.example.com/files/9152d568-7e7c-11e6-a377-37cbfb190b4b | |||
|
|||
### POST /files/archive | |||
|
|||
Create an archive and download it. The body of the request lists the files and | |||
Create an archive. The body of the request lists the files and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be difficult to have content negotiation on that endpoint? When the client asks for application/vnd.api+json
(JSON-API), the stack gives it a link for downloading the archive. But if it asks anything else, the stack sends the archive directly. I think it can be easier for apps that are not in a browser to have the possibility to download the archive in one request and not two.
docs/files.md
Outdated
} | ||
``` | ||
|
||
### GET /files/archive/:key/:name? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the ?
} | ||
|
||
func (s *memStore) AddFile(f string) (string, error) { | ||
fref := &fileRef{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe before adding a file, we should remove all the filesRef that have expired in s.Files
to avoid memory leak
return key, nil | ||
} | ||
|
||
func (s *memStore) AddArchive(a *Archive) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the same for archive
docs/files.md
Outdated
@@ -62,7 +62,7 @@ Location: http://cozy.example.com/files/6494e0ac-dfcb-11e5-88c1-472e84a9cbee | |||
"type": "io.cozy.files", | |||
"id": "6494e0ac-dfcb-11e5-88c1-472e84a9cbee", | |||
"meta": { | |||
"rev": "1-ff3beeb456eb" | |||
"rev": "1-ff3beeb456eb", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JSON, the trailing comma is not allowed...
docs/files.md
Outdated
}, | ||
"data": [ | ||
{ "type": "io.cozy.playlists", "id": "94375086-e2e2-11e6-81b9-5bc0b9dd4aa4" } | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the example of referenced_by
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad merge I suppose. fixing now
docs/files.md
Outdated
@@ -317,9 +309,6 @@ Location: http://cozy.example.com/files/9152d568-7e7c-11e6-a377-37cbfb190b4b | |||
**Note**: for an image, the links section will also include a link called | |||
`thumbnail` to the thumbnail URL of the image. | |||
|
|||
**Note**: see [references of documents in VFS](references-docs-in-vfs.md) for | |||
more informations about the references field. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this note?
docs/files.md
Outdated
```http | ||
GET /files/archive/4521DC87 HTTP/1.1 | ||
Accept: application/zip | ||
+Content-Length: 12345 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a +
to remove
pkg/vfs/download_store.go
Outdated
const downloadStoreTTL = 1 * time.Hour | ||
const downloadStoreCleanInterval = 1 * time.Hour | ||
|
||
var storeStore map[string]*memStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maps
are not thread safe, you should have a mutex around this one since it is used concurrently
pkg/vfs/download_store.go
Outdated
type memStore struct { | ||
Archives map[string]*Archive | ||
Files map[string]*fileRef | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this memStore should also have at least one mutex to protect read/writes from Archives
and Files
fields
} | ||
|
||
func (s *memStore) GetFile(k string) (string, error) { | ||
s.Mutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use defer s.Mutex.Unlock()
to avoid a deadlock on error branches where the lock is not unlocked.
} | ||
|
||
func (s *memStore) GetArchive(k string) (*Archive, error) { | ||
s.Mutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
} | ||
|
||
func cleanDownloadStore() { | ||
storeStoreMutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would use a defer Unlock()
on all locking methods (even the correct ones), for clarity
b78f3d2
to
198a57b
Compare
pkg/vfs/download_store.go
Outdated
} | ||
|
||
type memStore struct { | ||
Mutex *sync.Mutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sync.Mutex
are meant to be used as non-pointers that way you do not need to initialize them when creating a var mutex or struct containing one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More infos in this post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 2689490 Thanks for the link !
198a57b
to
2689490
Compare
No description provided.