src/lib/tree.c
TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node)
{
   char *p;
   int len;
   TREE_NODE *cd;
   char save_char;
   int match;

   if (*path == 0) {
      return node;
   }
   /* Check the current segment only */
   if ((p = first_path_separator(path)) != NULL) {
      len = p - path;
   } else {
      len = strlen(path);
   }
   Dmsg2(100, "tree_relcwd: len=%d path=%s\n", len, path);
   foreach_child(cd, node) {
      Dmsg1(100, "tree_relcwd: test cd=%s\n", cd->fname);
      if (cd->fname[0] == path[0] && len == (int)strlen(cd->fname)
          && strncmp(cd->fname, path, len) == 0) {
         break;
      }
      /* fnmatch has no len in call so we truncate the string */
      save_char = path[len];
      path[len] = 0;
      match = fnmatch(path, cd->fname, 0) == 0;
      path[len] = save_char;
      if (match) {
         break;
      }
   }
   if (!cd || (cd->type == TN_FILE && !tree_node_has_child(cd))) {
      return NULL;
   }
   if (!cd->can_access) {       /* Will display permission denied */
      return cd;
   }
   if (!p) {
      Dmsg0(100, "tree_relcwd: no more to lookup. found.\n");
      return cd;
   }
   Dmsg2(100, "recurse tree_relcwd with path=%s, cd=%s\n", p+1, cd->fname);
   /* Check the next segment if any */
   return tree_relcwd(p+1, root, cd);
}
/*
 * Do a relative cwd -- i.e. relative to current node rather than root node
 */
Do a relative cwd -- i.e. relative to current node rather than root node
Do a relative cwd -- i . e . relative to current node rather than root node
TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node)
{
   char *p;
   int len;
   TREE_NODE *cd;
   char save_char;
   int match;
   if (*path == 0) {
      return node;
   }
   if ((p = first_path_separator(path)) != NULL) {
      len = p - path;
   } else {
      len = strlen(path);
   }
   Dmsg2(100, "tree_relcwd: len=%d path=%s\n", len, path);
   foreach_child(cd, node) {
      Dmsg1(100, "tree_relcwd: test cd=%s\n", cd->fname);
      if (cd->fname[0] == path[0] && len == (int)strlen(cd->fname)
          && strncmp(cd->fname, path, len) == 0) {
         break;
      }
      save_char = path[len];
      path[len] = 0;
      match = fnmatch(path, cd->fname, 0) == 0;
      path[len] = save_char;
      if (match) {
         break;
      }
   }
   if (!cd || (cd->type == TN_FILE && !tree_node_has_child(cd))) {
      return NULL;
   }
   if (!cd->can_access) {       
      return cd;
   }
   if (!p) {
      Dmsg0(100, "tree_relcwd: no more to lookup. found.\n");
      return cd;
   }
   Dmsg2(100, "recurse tree_relcwd with path=%s, cd=%s\n", p+1, cd->fname);
   return tree_relcwd(p+1, root, cd);
}
TREE_NODE * tree_relcwd ( char * path , TREE_ROOT * root , TREE_NODE * node ) { char * p ; int len ; TREE_NODE * cd ; char save_char ; int match ; if ( * path == 0 ) { return node ; } if ( ( p = first_path_separator ( path ) ) != NULL ) { len = p - path ; } else { len = strlen ( path ) ; } Dmsg2 ( 100 , " \n " , len , path ) ; foreach_child ( cd , node ) { Dmsg1 ( 100 , " \n " , cd -> fname ) ; if ( cd -> fname [ 0 ] == path [ 0 ] && len == ( int ) strlen ( cd -> fname ) && strncmp ( cd -> fname , path , len ) == 0 ) { break ; } save_char = path [ len ] ; path [ len ] = 0 ; match = fnmatch ( path , cd -> fname , 0 ) == 0 ; path [ len ] = save_char ; if ( match ) { break ; } } if ( ! cd || ( cd -> type == TN_FILE && ! tree_node_has_child ( cd ) ) ) { return NULL ; } if ( ! cd -> can_access ) { return cd ; } if ( ! p ) { Dmsg0 ( 100 , " \n " ) ; return cd ; } Dmsg2 ( 100 , " \n " , p + 1 , cd -> fname ) ; return tree_relcwd ( p + 1 , root , cd ) ; }
Do a relative cwd -- i.e.
Do a relative cwd -- i . e .
/* Check the current segment only */ /* fnmatch has no len in call so we truncate the string */ /* Will display permission denied */ /* Check the next segment if any */