blob: b3b2c3ffc2090b641f5471c7b123e3ef469b731c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
require_once "database.php";
require_once "user.php";
/*path is in terms of the simulated filesystem*/
function get_directory(string $abstract_path,User $user)
{
global $database;
if($abstract_path[0]!="/")
{
return NULL;
}
if($component=strtok($abstract_path,"/")==false)
{
return $user->home_directory;
}
$current_dir=$database->get_node_id($component,$user->home_directory);
if($current_dir==NULL)
return NULL;
/*traverse path*/
while($component=strtok("/"))
{
$current_dir=$database->get_node_id($component,$current_dir);
if($current_dir==NULL)
return NULL;
}
return $current_dir;
}
/*returns an assoc arrat of Node-s*/
/*path is in terms of the simulated filesystem*/
function get_directory_contents(string $abstract_path,User $user)
{
global $database;
$dir_id=get_directory($abstract_path,$user);
if($dir_id==NULL)
return NULL;
return $database->get_links_of($dir_id);
}
/*path is in terms of the simulated filesystem*/
function create_directory(string $abstract_path,string $directory_name,string $note,User $user)
{
global $database;
$dir_id=$database->create_dangling_directory();
$parent_dir_id=get_directory($abstract_path,$user);
$database->link_nodes($parent_dir_id,$dir_id,$directory_name,$note);
}
?>
|