Exemplo n.º 1
0
bool is_ancestor_path(const char *ancestor, const char *path)
{
    char **path_components, **ancestor_components;
    int i, path_count, ancestor_count;
    bool result = false;

    path_components = split_path(path, &path_count);
    ancestor_components = split_path(ancestor, &ancestor_count);

    if (!path_components || !ancestor_components) {
        goto exit;
    }

    if (ancestor_count >= path_count) {
        goto exit;
    }

    for (i = 0; i < ancestor_count; i++) {
        if (strcmp(path_components[i], ancestor_components[i]) != 0) {
            goto exit;
        }
    }

    result = true;

 exit:
    free(path_components);
    free(ancestor_components);
    return result;
}
Exemplo n.º 2
0
  std::vector<std::string> get_paths(const std::string& name, bool resolve, size_t* lineno = nullptr) {
    std::string paths_str = get_string(name, lineno);

    std::vector<std::string> paths;
    split_path(paths_str.c_str(), ":", &paths);

    std::vector<std::pair<std::string, std::string>> params;
    params.push_back({ "LIB", kLibParamValue });
    if (target_sdk_version_ != 0) {
      char buf[16];
      async_safe_format_buffer(buf, sizeof(buf), "%d", target_sdk_version_);
      params.push_back({ "SDK_VER", buf });
    }

    static std::string vndk = Config::get_vndk_version_string('-');
    params.push_back({ "VNDK_VER", vndk });

    for (auto&& path : paths) {
      format_string(&path, params);
    }

    if (resolve) {
      std::vector<std::string> resolved_paths;

      // do not remove paths that do not exist
      resolve_paths(paths, &resolved_paths);

      return resolved_paths;
    } else {
      return paths;
    }
  }
Exemplo n.º 3
0
void http_serve(int fd, const char *name)
{
    void (*handler)(int, const char *) = http_serve_none;
    char pn[1024];
    struct stat st;

    getcwd(pn, sizeof(pn));
    setenv("DOCUMENT_ROOT", pn, 1);

    strcat(pn, name);
    split_path(pn);

    if (!stat(pn, &st))
    {
        /* executable bits -- run as CGI script */
        if (S_ISREG(st.st_mode) && (st.st_mode & S_IXUSR))
            handler = http_serve_executable;
        else if (S_ISDIR(st.st_mode))
            handler = http_serve_directory;
        else
            handler = http_serve_file;
    }

    handler(fd, pn);
}
Exemplo n.º 4
0
bool file_utils::full_path(dynamic_string &path)
{
#if defined(PLATFORM_WINDOWS)
    char buf[1024];
    char *p = _fullpath(buf, path.get_ptr(), sizeof(buf));
    if (!p)
        return false;
#else
    char buf[PATH_MAX];
    char *p;
    dynamic_string pn, fn;
    split_path(path.get_ptr(), pn, fn);
    if ((fn == ".") || (fn == ".."))
    {
        p = realpath(path.get_ptr(), buf);
        if (!p)
            return false;
        path.set(buf);
    }
    else
    {
        if (pn.is_empty())
            pn = "./";
        p = realpath(pn.get_ptr(), buf);
        if (!p)
            return false;
        combine_path(path, buf, fn.get_ptr());
    }
#endif

    return true;
}
Exemplo n.º 5
0
std::vector<xml_node_t*> xml_node_t::get_nodes( const std::string&        path,
                           const std::string&        parm_name,
                           const std::string&        parm_value )
{
  std::vector<xml_node_t*> nodes;
  if ( path.empty() || path == name_str )
  {
    xml_parm_t* parm = get_parm( parm_name );
    if ( parm && parm -> value_str == parm_value )
    {
      nodes.push_back( this );
    }
  }
  else
  {
    std::string name_str;
    xml_node_t* node = split_path( name_str, path );
    if ( ! node ) return nodes;

    for ( size_t i = 0; i < children.size(); ++i )
    {
      if ( node -> children[ i ] )
      {
        std::vector<xml_node_t*> n = node -> children[ i ] -> get_nodes( name_str, parm_name, parm_value );
        nodes.insert( nodes.end(), n.begin(), n.end() );
      }
    }
  }

  return nodes;
}
Exemplo n.º 6
0
int			deal_with_command(t_lst *node, char **arg)
{
	char			**path;
	char			*right_path;
	char			**env;

	env = get_env(node);
	path = (char **)malloc(sizeof(char *) * 7);
	if (!path)
		return (-1);
	path = split_path(node);
	if (path && *arg && env)
	{
		right_path = check_path(path, *arg);
		if (right_path)
		{
			exec_right_path(node, arg, env, right_path);
			return (-1);
		}
	}
	if (*arg && env)
	{
		right_path = "";
		check_command(node, arg, right_path, env);
		ft_strdel(arg);
	}
	return (-1);
}
Exemplo n.º 7
0
        std::auto_ptr<const parameter_reader_t> parameter_reader_t::get_child(const std::string& path) const
        {
            std::string name;
            std::string subpath;
            boost::tie(name, subpath) = split_path(path);

            if( path.empty() )
            {
                PRX_FATAL_S("Calling get child with empty path");
            }

            else if( subpath.empty() ) // No slash found
            {
                return std::auto_ptr<const parameter_reader_t > (get_subreader(path));
            }
            else
            {
                if( !has_element(name) )
                    PRX_WARN_S("Can't follow path \"" << path << "\" from " << trace());

                const parameter_reader_t* subreader = get_subreader(name);
                std::auto_ptr<const parameter_reader_t> child_reader = subreader->get_child(subpath);
                delete subreader;
                return child_reader;
            }
        }
Exemplo n.º 8
0
static int
postgresqlfs_mkdir(const char *path, mode_t mode __attribute__((unused)))
{
	struct dbpath dbpath;

	split_path(path, &dbpath);

	// TODO: use mode sensibly

	if (dbpath_is_root(dbpath))
		return -EEXIST;
	else if (dbpath_is_database(dbpath))
		return db_command(dbconn, "CREATE DATABASE %s;", dbpath.database);
	else {
		/* Note: Don't switch the database when creating a database. */
		if (!switch_database(&dbpath))
			return -EIO;

		if (dbpath_is_schema(dbpath))
			return db_command(dbconn, "CREATE SCHEMA %s;", dbpath.schema);
		else if (dbpath_is_table(dbpath))
			return -ENOSYS; /* maybe: create zero column table */
		else if (dbpath_is_row(dbpath))
			return -ENOSYS; /* maybe: translate to INSERT with primary key and default values? */
		else
			return -ENOENT;
	}
}
Exemplo n.º 9
0
Arquivo: myfs.c Projeto: anxolerd/myfs
static int myfs2_link(const char* to, const char* from) {
  struct Inode *node = lookup(to);
  node->n_links++;
  
  char* parent = calloc(1, BLOCK_SIZE);
  char* leaf = calloc(1, BLOCK_SIZE);

  split_path(from, parent, leaf);

  struct Inode *parent_dir = lookup(parent);
  
  int block_id = parent_dir->size / 4;
  int pos = parent_dir->size % 4;
  if (!pos) {
    parent_dir->blocks[block_id] = calloc(1, BLOCK_SIZE);
  }
  parent_dir->size = parent_dir->size + 1;

  void *ptr = parent_dir->blocks[block_id] + pos*sizeof(struct DirRecord);
  struct DirRecord *rec = (struct DirRecord*) ptr;

  rec->inode_id = get_inode_id(node);
  strcpy(rec->name, leaf);

  return 0;
}
Exemplo n.º 10
0
// Find the inode number for a file by its full path.
// This is the functionality that ext2cat ultimately needs.
__u32 get_inode_by_path(void * fs, char * path) {
    int num_slashes = get_number_of_slashes(path);
    char ** pathComponents = split_path(path);
    struct ext2_inode * dir = get_root_dir(fs);
    __u32 inode = 0;
    // loop through each part of path to file
    for (int i = 0; i < num_slashes; i++) {
        // look up inode of ith part of path
        inode = get_inode_from_dir(fs, dir, pathComponents[i]);
        // check if invalid
        if (inode == 0) {
            return 0;
        }
        // unless last iteration update inode entry to next file/directory
        if (i < num_slashes - 1) {
            dir = get_inode(fs,inode);
            // can't find right constant for this (value for dir is 16832)
            // so going to leave out error checking for now
            //if (dir->i_mode != LINUX_S_IFDIR) {
                 // error path is too long
            //     printf("Error path is too long\n");
            //     return 0;
            //}
        }
    }

    return inode;
}
Exemplo n.º 11
0
bool TestPathops::process ()
{
#ifdef _MSC_VER
    const char* paths [] = {"\\kokos\\banan", "d:\\Encyclopedia\\Data\\Genomes\\E.coli.K12\\proteins\\fasta\\", "", "\\", "\\ananas\\", NULL};
#else
    const char* paths [] = {"/kokos/banan", "~/Encyclopedia/Data/Genomes/E.coli.K12/proteins/fasta/", "", "/", "/ananas/", NULL};
#endif
    const char** path = paths;
    for (; *path != NULL; path ++)
    {
        o_ << "Path " << *path << std::endl;
        StrVec comps = split_path (*path);
        o_ << "path " << *path << ", " << comps.size () << " components" << std::endl;
        StrVec::const_iterator i = comps.begin ();
        for (;i < comps.end (); i ++)
            o_ << "  '" << (*i).c_str () << "'" << std::endl;
        std::string rejoined = join_path (comps);
        o_ << "  Rejoined: " << rejoined.c_str () << std::endl;
    }

    std::string jp = join_path ("kokos", "banan", "ananas", "yabloko", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("", "kokos", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("kokos", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path (NULL);
    o_ << jp.c_str () << std::endl;
    return true;
}
Exemplo n.º 12
0
void simple_controller_t::remove_system(const std::string& path)
{
    std::string name;
    std::string subpath;
    boost::tie(name, subpath) = split_path(path);

    PRX_DEBUG_S("--- REMOVE system : name : " << name << "  subpath : " << subpath);
    if( subsystems.find(name) != subsystems.end() )
        if( subpath.empty() )
        {
            PRX_ERROR_S("Trying to remove system from a simple controller.  Throwing exception...");
            throw simple_add_remove_exception();
        }
        else
        {
            try
            {
                subsystems[name]->remove_system(subpath);
            }
            catch( removal_exception e )
            {
                subsystems.erase(name);
            }
        }

    else
        throw invalid_path_exception("The system " + name + " does not exist in the path " + pathname);

    construct_spaces();
    verify();
}
Exemplo n.º 13
0
void simple_controller_t::add_system(const std::string& path, system_ptr_t system)
{
    std::string name;
    std::string subpath;
    boost::tie(name, subpath) = split_path(path);

    PRX_DEBUG_S("+++ ADD system : name : " << name << "  subpath: " << subpath);
    if( name.empty() )
        throw invalid_path_exception("Name is empty");
    else if( subpath.empty() )
    {
        PRX_ERROR_S("Trying to add system to a simple controller.  Throwing exception...");
        throw simple_add_remove_exception();
    }
    else if( !subpath.empty() )
    {
        if( subsystems.find(name) != subsystems.end() )
            subsystems[name]->add_system(subpath, system);
    }
    else
        throw invalid_path_exception(path);

    construct_spaces();
    verify();
}
Exemplo n.º 14
0
Arquivo: zipk.cpp Projeto: wangch/zipk
static int add_node(node* n, const std::wstring& path) {
   std::vector<std::wstring> vp;
   bool is_folder = split_path(path, vp);

   node* r = g_lv.root;
   std::vector<std::wstring>::iterator itt = vp.begin();
   for (; itt != vp.end(); ++itt) {
      std::vector<node*>::iterator it = r->childs.begin();
      bool found = false;
      for (; it != r->childs.end(); ++it) {
         node* c = *it;
         if (*itt == c->name) {
            c->p = r;
            r = c;
            found = true;
            break;
         }
      }
      if (!found) {
         std::vector<std::wstring>::iterator ittt = vp.end();
         --ittt;
         if (ittt != itt) { 
            node* c = new node;
            c->name = *itt;
            c->p = r;
            c->type = 0;
            c->time = n->time;
            r->childs.push_back(c);
            r = c;
         } else {
            n->name = *itt;
            if (is_folder) {
               n->type = 0;
               n->size = 0;
            } else {
               n->type = 2;
               wchar_t* suffix[] = { L"jpg", L"jpeg", L"png", L"bmp", L"gif", L"tif", L"tiff"};
               int pos = n->name.find(L'.');
               if (pos != std::wstring::npos) {
                  std::wstring sf = n->name.substr(pos+1);
                  sf = to_lower(sf);
                  for (int i  = 0; i < 7; ++i) {
                     if (sf == suffix[i]) {
                        n->type = 1;
                        if (i == 4) {
                           n->gif = true;
                        }
                        break;
                     }
                  }
               }
            }
            n->p = r;
            r->childs.push_back(n);
            break;
         }
      }
   }
   return 0;
}
Exemplo n.º 15
0
static int object_create_entry(const char *entry, const char *url)
{
	struct strbuf buf = STRBUF_INIT;
	char *args[3], path[PATH_MAX];
	int nr, ret = -EINVAL;
	uint64_t size;

	nr = split_path(entry, ARRAY_SIZE(args), args);
	if (nr != ARRAY_SIZE(args)) {
		sheepfs_pr("Invalid argument %d, %s", nr, entry);
		goto out;
	}

	strbuf_addf(&buf, "%s", PATH_HTTP);
	for (int i = 0; i < nr; i++) {
		strbuf_addf(&buf, "/%s", args[i]);
		snprintf(path, sizeof(path), "%.*s", (int)buf.len, buf.buf);
		if (i == (nr - 1)) {
			if (shadow_file_create(path) < 0) {
				sheepfs_pr("Create file %s fail", path);
				goto out;
			}
			size = curl_get_object_size(url);
			if (size <= 0) {
				sheepfs_pr("Failed to get size of object");
				shadow_file_delete(path);
				goto out;
			}
			if (shadow_file_setxattr(path, HTTP_SIZE_NAME, &size,
						 HTTP_SIZE_SIZE) < 0) {
				sheepfs_pr("Failed to setxattr for %s",
				       HTTP_SIZE_NAME);
				shadow_file_delete(path);
				goto out;
			}
			if (sheepfs_set_op(path, OP_OBJECT) < 0) {
				sheepfs_pr("Set_op %s fail", path);
				shadow_file_delete(path);
				goto out;
			}
		} else {
			if (shadow_dir_create(path) < 0) {
				sheepfs_pr("Create dir %s fail", path);
				goto out;
			}
			if (sheepfs_set_op(path, OP_CONTAINER) < 0) {
				sheepfs_pr("Set_op %s fail", path);
				shadow_dir_delete(path);
				goto out;
			}
		}
	}
	ret = 0;
out:
	for (int i = 0; i < ARRAY_SIZE(args); i++)
		free(args[i]);
	strbuf_release(&buf);
	return ret;
}
Exemplo n.º 16
0
static int
postgresqlfs_unlink(const char *path)
{
	struct dbpath dbpath;

	split_path(path, &dbpath);

	return -EPERM;
}
Exemplo n.º 17
0
    LIBUPCOREAPI UPALLOC UPWARNRESULT
    wchar_t* dirname(wchar_t const* p, size_t n) noexcept {
        split_result<wchar_t> result;
        if (split_path(p, n, &result)) {
            return nullptr;
        }

        return wcsndup(result.dirname, result.dirname_length);
    }
Exemplo n.º 18
0
static int
postgresqlfs_getattr(const char *path, struct stat *buf)
{
	struct dbpath dbpath;

	buf->st_mode = 0;

	debug("path=%s", path);

	split_path(path, &dbpath);

	debug("%s", dbpath_to_string(&dbpath));

	if (!dbpath_is_database(dbpath) && !switch_database(&dbpath))
		return -EIO;

	if (!dbpath_exists(&dbpath, dbconn))
		return -ENOENT;

	buf->st_nlink = 1;
	buf->st_uid = getuid();
	buf->st_gid = getgid();

	if (dbpath_is_column(dbpath))
		buf->st_mode |= S_IFREG | 0444;
	else
		buf->st_mode |= S_IFDIR | 0755;

	buf->st_atime = starttime;
	buf->st_mtime = starttime;
	buf->st_ctime = starttime;

	buf->st_blksize = 1;

	if (dbpath_is_column(dbpath))
	{
		PGresult *res;

		res = db_query(dbconn,
					   "SELECT octet_length(CAST(%s AS text)) FROM %s.%s WHERE ctid = '%s';",
					   dbpath.column + 3, dbpath.schema, dbpath.table, rowname_to_ctid(dbpath.row));
		if (!res)
			return -EIO;

		buf->st_size = atol(PQgetvalue(res, 0, 0));

		PQclear(res);
	}
	else
	{
		buf->st_size = 42;
	}

	buf->st_blocks = buf->st_size;

	return 0;
}
Exemplo n.º 19
0
SegmentsVec path_to_segments(const std::string& path) {
    SegmentsVec segments{};

    for (const auto& chunk : split_path(path)) {
        segments.emplace_back(mux::path_segment_to_matcher(chunk));
    }

    return segments;
}
Exemplo n.º 20
0
bool file_utils::get_filename(const char *p, dynamic_string &filename)
{
    dynamic_string temp_ext;
    if (!split_path(p, NULL, NULL, &filename, &temp_ext))
        return false;

    filename += temp_ext;
    return true;
}
Exemplo n.º 21
0
bool file_utils::get_pathname(const char *p, dynamic_string &path)
{
    dynamic_string temp_drive, temp_path;
    if (!split_path(p, &temp_drive, &temp_path, NULL, NULL))
        return false;

    combine_path(path, temp_drive.get_ptr(), temp_path.get_ptr());
    return true;
}
Exemplo n.º 22
0
	void file_storage::add_file(std::string const& file, size_type size, int flags
		, std::time_t mtime, std::string const& symlink_path)
	{
		TORRENT_ASSERT(size >= 0);
		if (size < 0) size = 0;
		if (!has_parent_path(file))
		{
			// you have already added at least one file with a
			// path to the file (branch_path), which means that
			// all the other files need to be in the same top
			// directory as the first file.
			TORRENT_ASSERT(m_files.empty());
			m_name = file;
		}
		else
		{
			if (m_files.empty())
				m_name = split_path(file).c_str();
		}
		TORRENT_ASSERT(m_name == split_path(file).c_str());
		m_files.push_back(internal_file_entry());
		internal_file_entry& e = m_files.back();
		e.set_name(file.c_str());
		e.size = size;
		e.offset = m_total_size;
		e.pad_file = (flags & pad_file) != 0;
		e.hidden_attribute = (flags & attribute_hidden) != 0;
		e.executable_attribute = (flags & attribute_executable) != 0;
		e.symlink_attribute = (flags & attribute_symlink) != 0;
		if (e.symlink_attribute)
		{
			e.symlink_index = m_symlinks.size();
			m_symlinks.push_back(symlink_path);
		}
		if (mtime)
		{
			if (m_mtime.size() < m_files.size()) m_mtime.resize(m_files.size());
			m_mtime[m_files.size() - 1] = mtime;
		}
		
		update_path_index(e);
		m_total_size += size;
	}
Exemplo n.º 23
0
static krb5_error_code KRB5_CALLCONV
dcc_resolve(krb5_context context, krb5_ccache *cache_out, const char *residual)
{
    krb5_error_code ret;
    krb5_ccache fcc;
    char *primary_path = NULL, *sresidual = NULL, *dirname, *filename;

    *cache_out = NULL;

    if (*residual == ':') {
        /* This is a subsidiary cache within the directory. */
        ret = split_path(context, residual + 1, &dirname, &filename);
        if (ret)
            return ret;

        ret = verify_dir(context, dirname);
        free(dirname);
        free(filename);
        if (ret)
            return ret;
    } else {
        /* This is the directory itself; resolve to the primary cache. */
        ret = verify_dir(context, residual);
        if (ret)
            return ret;

        ret = primary_pathname(residual, &primary_path);
        if (ret)
            goto cleanup;

        ret = read_primary_file(context, primary_path, residual, &sresidual);
        if (ret == ENOENT) {
            /* Create an initial primary file. */
            ret = write_primary_file(primary_path, "tkt");
            if (ret)
                goto cleanup;
            ret = subsidiary_residual(residual, "tkt", &sresidual);
            if (ret)
                goto cleanup;
        }
        residual = sresidual;
    }

    ret = krb5_fcc_ops.resolve(context, &fcc, residual + 1);
    if (ret)
        goto cleanup;
    ret = make_cache(residual, fcc, cache_out);
    if (ret)
        krb5_fcc_ops.close(context, fcc);

cleanup:
    free(primary_path);
    free(sresidual);
    return ret;
}
Exemplo n.º 24
0
xml_node_t* xml_node_t::get_node( const std::string& path,
                                  const std::string& parm_name,
                                  const std::string& parm_value )
{
  std::string name_str;
  xml_node_t* node = split_path( name_str, path );

  if ( node ) node = node -> search_tree( name_str, parm_name, parm_value );

  return node;
}
Exemplo n.º 25
0
bool file_utils::split_path(const char *p, dynamic_string &path, dynamic_string &filename)
{
    dynamic_string temp_drive, temp_path, temp_ext;
    if (!split_path(p, &temp_drive, &temp_path, &filename, &temp_ext))
        return false;

    filename += temp_ext;

    combine_path(path, temp_drive.get_ptr(), temp_path.get_ptr());
    return true;
}
Exemplo n.º 26
0
char *interpret_args(int argc, char *argv[]) {
	const char *HELP_TEXT =
		"Syntax: podcastgen <options> <input file>\n"
		"\n"
		"	-h, --help\t\tDisplay this help text\n"
		"	-v\t\t\tVerbose output\n"
		"	-C\t\t\tSet the Low Energy Coefficient\n"
		"	-T\t\t\tSet the Upper Music Threshold\n"
		"	--very-verbose\t\tVERY verbose output\n"
		"	--no-intro\t\tRemove music at start of file\n\n";

	static struct option long_options[] = {
		{"help", no_argument, NULL, 'h'},
		{"very-verbose", no_argument, (int*) &very_verbose, true},
		{"no-intro", no_argument, (int*) &has_intro, false}
	};

	int opt;
	while ((opt = getopt_long(argc, argv, "vhC:T:", long_options, NULL)) != -1) {
		switch (opt) {
			case 'v':
				verbose = true;
				break;
			case 'h':
				printf(HELP_TEXT);
				exit(0);
			case 'C':
				LOW_ENERGY_COEFFICIENT = atof(optarg);
				break;
			case 'T':
				UPPER_MUSIC_THRESHOLD = atof(optarg);
				break;
			case '?':
				logger(ERROR, "Unknown argument \'-%c\'.", optopt);
				exit(1);
		}
	}

	if (very_verbose) {
		verbose = true;
	}

	if (argc-optind == 1) {
		input_path = malloc(100);
		file_folders = malloc(100);
		filename = malloc(100);

		strcpy(input_path, argv[optind]);
		split_path(input_path, &file_folders, &filename);
	} else {
		logger(ERROR, "Please supply a source file.");
		exit(1);
	}
}
Exemplo n.º 27
0
xml_node_t* xml_node_t::get_node( const std::string& path )
{
  if ( path.empty() || path == name_str )
    return this;

  std::string name_str;
  xml_node_t* node = split_path( name_str, path );

  if ( node ) node = node -> search_tree( name_str );

  return node;
}
Exemplo n.º 28
0
int ext2_remove_file(uint8_t *fs, char *path) {
    uint32_t inum = get_inode_by_path(fs, path);
    if (!inum) {
        DEBUG("Bad path");
        return 0;
    }
    struct ext2_inode *inode = get_inode(fs, inum);
    // check if file
    if (!ext2_inode_has_mode(inode, EXT2_S_IFREG)) {
        DEBUG("FILE DELETE: Not a file %x", inode->i_mode);
        return 0;
    }
    // get directory path
    int num_parts = 0;
    char **parts = split_path(path, &num_parts);
    if (!num_parts) {
        DEBUG("No parts");
        return 0;
    }
    int newstring_size = 0;
    for (int i=0; i < num_parts-1; i++) {
        newstring_size += strlen(parts[i]) + 1;
    }

    char* newstring = malloc(newstring_size);
    strcpy(newstring, "/");
    for (int i=0; i < num_parts-1; i++) {
        strcat(newstring,parts[i]);
        if (i != num_parts-2) {
            strcat(newstring, "/");
        }
    }

    // get inode of directory
    int dir_num = 0;
    if(strcmp(newstring, "/")) {
        dir_num = get_inode_by_path(fs, newstring);
    }
    else {
        dir_num = EXT2_ROOT_INO;
    }

    // create dentry
    if (dir_num) {
        dentry_remove(fs, dir_num, inum);
    }
    else {
        DEBUG("Bad dir path");
        return 0;
    }

    return 1;
}
Exemplo n.º 29
0
/* Build a machine dependent library name out of a path and file name.  */
void
md_build_library_name(char *holder, int holderlen, char *pname, char *fname)
{
    int n;
    int i;
    char  c;
    char  **pelements;
    const int pnamelen = pname ? (int)strlen(pname) : 0;
    c = (pnamelen > 0) ? pname[pnamelen-1] : 0;

    /* Quietly truncates on buffer overflow. Should be an error. */
    if (pnamelen + strlen(fname) + 10 > (unsigned int)holderlen) {
        *holder = '\0';
        return;
    }

    if (pnamelen == 0) {
        md_snprintf(holder, holderlen, "%s.dll", fname);
    } else if (c == ':' || c == '\\') {
        md_snprintf(holder, holderlen, "%s%s.dll", pname, fname);
    } else if (strchr(pname, PATH_SEPARATOR_CHAR) != NULL) {
        pelements = split_path(pname, &n);
        for (i = 0 ; i < n ; i++) {
            char* path = pelements[i];
            char lastchar;
            // really shouldn't be NULL but what the heck, check can't hurt
            size_t plen = (path == NULL) ? 0 : strlen(path);
            if (plen == 0) {
                continue; // skip empty path values
            }
            lastchar = path[plen - 1];
            if (lastchar == ':' || lastchar == '\\') {
                md_snprintf(holder, holderlen, "%s%s.dll", pelements[i], fname);
            } else {
                md_snprintf(holder, holderlen, "%s\\%s.dll", pelements[i], fname);
            }
            if (GetFileAttributes(holder) != INVALID_FILE_ATTRIBUTES) {
                break;
            }
        }
        // release the storage
        for (i = 0 ; i < n ; i++) {
           if (pelements[i] != NULL) {
              free(pelements[i]);
	   }
        }
        if (pelements != NULL) {
           free(pelements);
	}
    } else {
        md_snprintf(holder, holderlen, "%s\\%s.dll", pname, fname);
    }
}
Exemplo n.º 30
0
int
guestfs_impl_copy_in (guestfs_h *g, const char *localpath, const char *remotedir)
{
  CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
  int fd;
  int r;
  char fdbuf[64];
  size_t buf_len = strlen (localpath) + 1;
  char buf[buf_len];
  const char *dirname, *basename;

  int remote_is_dir = guestfs_is_dir (g, remotedir);
  if (remote_is_dir == -1)
    return -1;

  if (!remote_is_dir) {
    error (g, _("target '%s' is not a directory"), remotedir);
    return -1;
  }

  if (split_path (g, buf, buf_len, localpath, &dirname, &basename) == -1)
    return -1;

  guestfs_int_cmd_add_arg (cmd, "tar");
  if (dirname) {
    guestfs_int_cmd_add_arg (cmd, "-C");
    guestfs_int_cmd_add_arg (cmd, dirname);
  }
  guestfs_int_cmd_add_arg (cmd, "-cf");
  guestfs_int_cmd_add_arg (cmd, "-");
  guestfs_int_cmd_add_arg (cmd, basename);

  r = guestfs_int_cmd_run_async (cmd, NULL, NULL, &fd, NULL);
  if (r == -1)
    return -1;

  snprintf (fdbuf, sizeof fdbuf, "/dev/fd/%d", fd);

  r = guestfs_tar_in (g, fdbuf, remotedir);

  if (close (fd) == -1) {
    perrorf (g, "close (tar subprocess)");
    return -1;
  }

  r = guestfs_int_cmd_wait (cmd);
  if (r == -1)
    return -1;
  if (!(WIFEXITED (r) && WEXITSTATUS (r) == 0))
    return -1;

  return 0;
}