@@ -46,6 +46,7 @@ let trash_directory = "/.Trash"
4646let trash_directory_name_length = String. length trash_directory
4747let trash_directory_base_path = " /.Trash/"
4848let lost_and_found_directory = " /lost+found"
49+ let shared_with_me_directory = " /.shared"
4950let f_bsize = 4096L
5051let change_limit = 50
5152let max_link_target_length = 127
@@ -119,10 +120,22 @@ let is_in_trash_directory path =
119120 if path = trash_directory then false
120121 else ExtString.String. starts_with path trash_directory_base_path
121122
122- let is_lost_and_found path config =
123- if not config.Config. lost_and_found then false
123+ let is_lost_and_found_root path trashed config =
124+ if trashed || not config.Config. lost_and_found then false
125+ else path = lost_and_found_directory
126+
127+ let is_lost_and_found path trashed config =
128+ if trashed || not config.Config. lost_and_found then false
124129 else ExtString.String. starts_with path lost_and_found_directory
125130
131+ let is_shared_with_me_root path trashed config =
132+ if trashed || not config.Config. shared_with_me then false
133+ else path = shared_with_me_directory
134+
135+ let is_shared_with_me path trashed config =
136+ if trashed || not config.Config. shared_with_me then false
137+ else ExtString.String. starts_with path shared_with_me_directory
138+
126139let get_path_in_cache path =
127140 if path = root_directory then
128141 (root_directory, false )
@@ -259,8 +272,8 @@ let create_root_resource trashed =
259272 trashed = Some trashed;
260273 }
261274
262- let create_lost_and_found_resource () =
263- let resource = create_resource lost_and_found_directory in
275+ let create_well_known_resource path =
276+ let resource = create_resource path in
264277 { resource with
265278 Cache.Resource. remote_id = Some " " ;
266279 mime_type = Some folder_mime_type;
@@ -403,15 +416,17 @@ let get_well_known_resource path trashed =
403416 let context = Context. get_ctx () in
404417 let cache = context.Context. cache in
405418 let config = context |. Context. config_lens in
406- match lookup_resource root_directory trashed with
419+ match lookup_resource path trashed with
407420 | None ->
408421 let (well_known_resource, label) =
409422 if path = root_directory then
410423 (create_root_resource trashed, " root" )
411- else if path = lost_and_found_directory &&
412- config.Config. lost_and_found then
413- (create_lost_and_found_resource () , " lost+found" )
414- else invalid_arg (" Invalid well known path: " ^ path)
424+ else if is_lost_and_found_root path trashed config then
425+ (create_well_known_resource lost_and_found_directory, " lost+found" )
426+ else if is_shared_with_me_root path trashed config then
427+ (create_well_known_resource shared_with_me_directory, " shared with me" )
428+ else invalid_arg (" Invalid well known path: " ^ path ^ " trashed=" ^
429+ (string_of_bool trashed))
415430 in
416431 Utils. log_with_header
417432 " BEGIN: Saving %s resource to db (id=%Ld)\n %!"
@@ -581,6 +596,7 @@ let get_metadata () =
581596
582597 let context = Context. get_ctx () in
583598 let cache = context.Context. cache in
599+ let config = context |. Context. config_lens in
584600
585601 let update_resource_cache new_metadata old_metadata =
586602 let get_all_changes =
@@ -742,9 +758,24 @@ let get_metadata () =
742758 (delete_cached_resources new_metadata);
743759 Utils. log_with_header " END: Removing deleted resources\n %!" ;
744760 if List. length changes > 0 then begin
745- Utils. log_with_header " BEGIN: Invalidating trash bin resource\n %!" ;
761+ Utils. log_with_header
762+ " BEGIN: Invalidating trash bin resource\n %!" ;
746763 Cache.Resource. invalidate_trash_bin cache;
747764 Utils. log_with_header " END: Invalidating trash bin resource\n %!" ;
765+ if config.Config. lost_and_found then begin
766+ Utils. log_with_header
767+ " BEGIN: Invalidating lost+found resource\n %!" ;
768+ Cache.Resource. invalidate_path cache lost_and_found_directory;
769+ Utils. log_with_header
770+ " END: Invalidating lost+found resource\n %!" ;
771+ end ;
772+ if config.Config. shared_with_me then begin
773+ Utils. log_with_header
774+ " BEGIN: Invalidating .shared resource\n %!" ;
775+ Cache.Resource. invalidate_path cache shared_with_me_directory;
776+ Utils. log_with_header
777+ " END: Invalidating .shared resource\n %!" ;
778+ end
748779 end ;
749780 SessionM. return {
750781 new_metadata with
@@ -966,11 +997,14 @@ and get_resource path trashed =
966997 let root_resource =
967998 get_well_known_resource root_directory trashed in
968999 SessionM. return root_resource
969- else if path = lost_and_found_directory && not trashed &&
970- config.Config. lost_and_found then
1000+ else if is_lost_and_found_root path trashed config then
9711001 let lost_and_found_resource =
9721002 get_well_known_resource lost_and_found_directory trashed in
9731003 SessionM. return lost_and_found_resource
1004+ else if is_shared_with_me_root path trashed config then
1005+ let shared_with_me_resource =
1006+ get_well_known_resource shared_with_me_directory trashed in
1007+ SessionM. return shared_with_me_resource
9741008 else
9751009 let cache = Context. get_cache () in
9761010 begin match lookup_resource path trashed with
@@ -1300,13 +1334,13 @@ let get_attr path =
13001334
13011335 if path = root_directory then
13021336 context.Context. mountpoint_stats
1303- else if path = trash_directory then
1337+ else if path = trash_directory ||
1338+ is_shared_with_me_root path trashed config then
13041339 let stats = context.Context. mountpoint_stats in
13051340 { stats with
1306- Unix.LargeFile. st_perm = stats.Unix.LargeFile. st_perm land 0o555
1341+ Unix.LargeFile. st_perm = stats.Unix.LargeFile. st_perm land 0o555
13071342 }
1308- else if path = lost_and_found_directory && not trashed &&
1309- config.Config. lost_and_found then
1343+ else if is_lost_and_found_root path trashed config then
13101344 context.Context. mountpoint_stats
13111345 else begin
13121346 let (resource, content_path) = do_request request_resource |> fst in
@@ -1427,26 +1461,7 @@ let read_dir path =
14271461 " BEGIN: Getting folder content (path=%s, trashed=%b)\n %!"
14281462 path_in_cache trashed;
14291463 get_resource path_in_cache trashed >> = fun resource ->
1430- get_folder_id path_in_cache trashed >> = fun folder_id ->
1431- let q =
1432- Printf. sprintf " '%s' in parents and trashed = %b" folder_id trashed in
1433- get_all_files q >> = fun files ->
1434- Utils. log_with_header
1435- " END: Getting folder content (path=%s, trashed=%b)\n %!"
1436- path_in_cache trashed;
1437- begin if path = trash_directory && trashed then begin
1438- Utils. log_with_header " BEGiN: Getting explicitly trashed files\n %!" ;
1439- let q =
1440- Printf. sprintf " not '%s' in parents and trashed = true" folder_id in
1441- get_all_files q >> = fun trashed_files ->
1442- let explicitly_trashed_files =
1443- List. filter (fun file -> file.File. explicitlyTrashed) trashed_files in
1444- Utils. log_with_header
1445- " END: Getting explicitly trashed files: Found %d files\n %!"
1446- (List. length explicitly_trashed_files);
1447- SessionM. return (files @ explicitly_trashed_files, resource);
1448- end else if path = lost_and_found_directory && not trashed &&
1449- config.Config. lost_and_found then begin
1464+ if is_lost_and_found_root path trashed config then begin
14501465 Utils. log_with_header " BEGiN: Getting lost and found files\n %!" ;
14511466 let q = " 'me' in owners" in
14521467 get_all_files q >> = fun all_owned_files ->
@@ -1458,8 +1473,36 @@ let read_dir path =
14581473 " END: Getting lost and found files: Found %d files\n %!"
14591474 (List. length lost_and_found_files);
14601475 SessionM. return (lost_and_found_files, resource);
1461- end else
1462- SessionM. return (files, resource);
1476+ end else if is_shared_with_me_root path trashed config then begin
1477+ Utils. log_with_header " BEGiN: Getting shared with me files\n %!" ;
1478+ let q = " sharedWithMe = true" in
1479+ get_all_files q >> = fun shared_with_me_files ->
1480+ Utils. log_with_header
1481+ " END: Getting shared with me files: Found %d files\n %!"
1482+ (List. length shared_with_me_files);
1483+ SessionM. return (shared_with_me_files, resource);
1484+ end else begin
1485+ get_folder_id path_in_cache trashed >> = fun folder_id ->
1486+ let q =
1487+ Printf. sprintf " '%s' in parents and trashed = %b" folder_id trashed in
1488+ get_all_files q >> = fun files ->
1489+ Utils. log_with_header
1490+ " END: Getting folder content (path=%s, trashed=%b)\n %!"
1491+ path_in_cache trashed;
1492+ begin if path = trash_directory && trashed then begin
1493+ Utils. log_with_header " BEGiN: Getting explicitly trashed files\n %!" ;
1494+ let q =
1495+ Printf. sprintf " not '%s' in parents and trashed = true" folder_id in
1496+ get_all_files q >> = fun trashed_files ->
1497+ let explicitly_trashed_files =
1498+ List. filter (fun file -> file.File. explicitlyTrashed) trashed_files in
1499+ Utils. log_with_header
1500+ " END: Getting explicitly trashed files: Found %d files\n %!"
1501+ (List. length explicitly_trashed_files);
1502+ SessionM. return (files @ explicitly_trashed_files, resource);
1503+ end else
1504+ SessionM. return (files, resource);
1505+ end
14631506 end
14641507 in
14651508
@@ -1533,6 +1576,11 @@ let read_dir path =
15331576 if path = root_directory then
15341577 (Filename. basename trash_directory) :: filenames
15351578 else filenames in
1579+ let filenames =
1580+ if path = root_directory && not trashed &&
1581+ config.Config. shared_with_me then
1582+ (Filename. basename shared_with_me_directory) :: filenames
1583+ else filenames in
15361584 if path = root_directory && not trashed &&
15371585 config.Config. lost_and_found then
15381586 (Filename. basename lost_and_found_directory) :: filenames
@@ -1833,8 +1881,9 @@ let create_remote_resource ?link_target is_folder path mode =
18331881
18341882 let context = Context. get_ctx () in
18351883 let config = context |. Context. config_lens in
1836- if is_lost_and_found path config && config.Config. lost_and_found
1837- then raise Permission_denied ;
1884+ if is_lost_and_found path trashed config ||
1885+ is_shared_with_me path trashed config then
1886+ raise Permission_denied ;
18381887
18391888 let cache = context.Context. cache in
18401889 let parent_path = Filename. dirname path_in_cache in
@@ -1930,6 +1979,12 @@ let check_if_empty remote_id is_folder trashed =
19301979let trash_resource is_folder trashed path =
19311980 if trashed then raise Permission_denied ;
19321981
1982+ let context = Context. get_ctx () in
1983+ let config = context |. Context. config_lens in
1984+ if is_lost_and_found path trashed config ||
1985+ is_shared_with_me path trashed config then
1986+ raise Permission_denied ;
1987+
19331988 let trash resource =
19341989 let remote_id = resource |. Cache.Resource. remote_id |> Option. get in
19351990 check_if_empty remote_id is_folder trashed >> = fun () ->
@@ -2035,12 +2090,12 @@ let rename path new_path =
20352090 if trashed <> target_trashed then raise Permission_denied ;
20362091
20372092 let config = Context. get_ctx () |. Context. config_lens in
2038- if ( path = lost_and_found_directory ||
2039- is_lost_and_found new_path config) &&
2040- not trashed &&
2041- not target_trashed &&
2042- config. Config. lost_and_found
2043- then raise Permission_denied ;
2093+ if is_lost_and_found_root path trashed config ||
2094+ is_lost_and_found new_path target_trashed config then
2095+ raise Permission_denied ;
2096+ if is_shared_with_me path trashed config ||
2097+ is_shared_with_me new_path target_trashed config then
2098+ raise Permission_denied ;
20442099
20452100 let old_parent_path = Filename. dirname path_in_cache in
20462101 let new_parent_path = Filename. dirname new_path_in_cache in
@@ -2097,9 +2152,7 @@ let rename path new_path =
20972152 new_parent_path target_trashed >> = fun new_parent_resource ->
20982153 let new_parent_id =
20992154 new_parent_resource.Cache.Resource. remote_id |> Option. get in
2100- begin if old_parent_path = lost_and_found_directory &&
2101- not trashed &&
2102- config.Config. lost_and_found then
2155+ begin if is_lost_and_found_root old_parent_path trashed config then
21032156 SessionM. return " "
21042157 else
21052158 get_resource
0 commit comments