function delete_edges_with($source = '*', $label = '*', $destination = '*')
{
    $paths = edges_with($source, $label, $destination);
    foreach ($paths as $link_path) {
        if (is_link($link_path)) {
            //Get the name of the parent label directory so that we can check whether it is empty after we delete the destination link.
            $label_path = dirname($link_path);
            //Remove the link itself.
            if (!unlink($link_path)) {
                $unlink_error = error_get_last();
                exit_with_error_json("Deletion of link \"" . $link_path . "\" failed: " . $unlink_error['message']);
            }
            //If the label directory is now empty, delete it.
            $remaining_destinations = glob($label_path . PATH_SEPARATOR . NODE_NAME_WILDCARD, GLOB_ONLYDIR);
            if ($remaining_destinations === FALSE) {
                $glob_error = error_get_last();
                exit_with_error_json("Check for destination symlinks in \"" . $label_path . "\" failed: " . $glob_error['message']);
            }
            if (count($remaining_destinations) < 1) {
                if (!rmdir($label_path)) {
                    $rmdir_error = error_get_last();
                    exit_with_error_json("Deletion of empty label directory \"" . $label_path . "\" failed: " . $rmdir_error['message']);
                }
                //end of if we failed to delete the empty label directory
            }
            //end of if the label folder is now empty.
        }
        //end of if the link exists and is a symbolic link
    }
    //end of loop through all edges found
}
Exemple #2
0
function edges_to($destination)
{
    return edges_with(NODE_NAME_WILDCARD, NODE_NAME_WILDCARD, $destination);
}
Exemple #3
0
    $node[EDGE] = $edge;
    $path_elements = explode(PATH_SEPARATOR, $edge);
    $name_index = count($path_elements) + $back_index;
    $name = $path_elements[$name_index];
    $node[NAME] = $path_elements[$name_index];
    $node[PATH] = node_path_with_name($name);
    return $node;
}
//end of function node_info_with_edge
//If the request specified all three, we do not have multiple possible matches.
//The edge either exists or does not exist.
if ($limit_by_source && $limit_by_label && $limit_by_destination) {
    $exists = edge_exists($source, $label, $destination);
    exit(json_encode(array('exists' => $exists)));
} elseif ($limit_by_source || $limit_by_label || $limit_by_destination) {
    $edges = edges_with($source, $label, $destination);
    if ($limit_by_source && $limit_by_label || $limit_by_source && $limit_by_destination || $limit_by_label && $limit_by_destination) {
        //In this case, we have only one wildcard in the edge, so get that as the name.
        //Recall that the last elements in the path describing an edge will be source/label/destination.
        //We will add each offset to the length of the array to get the index of the path element that is the name of the unspecified node.
        if ($limit_by_label && $limit_by_destination) {
            $back_index = -1;
            //The wildcard is the destination.
        } elseif ($limit_by_source && limit_by_destination) {
            $back_index = -2;
            //The wildcard is the label.
        } else {
            $back_index = -3;
            //The wildcard is the source.
        }
        foreach ($edges as $edge) {
Exemple #4
0
function edges_from($source)
{
    return edges_with($source, NODE_NAME_WILDCARD, NODE_NAME_WILDCARD);
}
Exemple #5
0
function edges_labeled($label)
{
    return edges_with(NODE_NAME_WILDCARD, $label, NODE_NAME_WILDCARD);
}