Skip to content

Commit

Permalink
Fix #36: Enable access to restricted files
Browse files Browse the repository at this point in the history
Restricted files cannot be downloaded by viewers, but they can be
downloaded by authorized apps.
  • Loading branch information
astrada committed Nov 3, 2013
1 parent 5d1a003 commit 36f9a4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
3 changes: 0 additions & 3 deletions src/cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -440,21 +440,18 @@ struct
| ToDownload
| ToUpload
| NotFound
| Restricted

let to_string = function
InSync -> "InSync"
| ToDownload -> "ToDownload"
| ToUpload -> "ToUpload"
| NotFound -> "NotFound"
| Restricted -> "Restricted"

let of_string = function
"InSync" -> InSync
| "ToDownload" -> ToDownload
| "ToUpload" -> ToUpload
| "NotFound" -> NotFound
| "Restricted" -> Restricted
| s -> failwith ("Resource state unexpected: " ^ s)

end
Expand Down
16 changes: 4 additions & 12 deletions src/drive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ let update_resource_from_file ?state resource file =
change_id = largest_change_id;
last_update = Unix.gettimeofday ();
path;
state =
if file.File.labels.File.Labels.restricted then
Cache.Resource.State.Restricted
else Option.default resource.Cache.Resource.state state;
state = Option.default resource.Cache.Resource.state state;
}

let get_parent_resource_ids file =
Expand Down Expand Up @@ -972,7 +969,7 @@ let download_resource resource =
Cache.Resource.update_resource cache updated_resource;
SessionM.return content_path
in
match resource.Cache.Resource.state with
begin match resource.Cache.Resource.state with
Cache.Resource.State.InSync
| Cache.Resource.State.ToUpload ->
if Sys.file_exists content_path then
Expand All @@ -986,13 +983,8 @@ let download_resource resource =
do_download ()
| Cache.Resource.State.NotFound ->
throw File_not_found
| Cache.Resource.State.Restricted ->
begin if not (Sys.file_exists content_path) then
create_empty_file ()
else
SessionM.return ()
end >>
SessionM.return content_path
end >>
SessionM.return content_path

let is_filesystem_read_only () =
Context.get_ctx () |. Context.config_lens |. Config.read_only
Expand Down

0 comments on commit 36f9a4b

Please sign in to comment.