Ejemplo n.º 1
0
Archivo: path.c Proyecto: jubalh/vifm
void
exclude_file_name(char path[])
{
	if(path_exists(path, DEREF) && !is_valid_dir(path))
	{
		remove_last_path_component(path);
	}
}
Ejemplo n.º 2
0
/* Tries to use $MYVIFMRC as configuration file.  Returns non-zero on success,
 * otherwise zero is returned. */
static int
try_myvifmrc_envvar_for_vifmrc(void)
{
	LOG_FUNC_ENTER;

	const char *myvifmrc = env_get(MYVIFMRC_EV);
	return myvifmrc != NULL && path_exists(myvifmrc, DEREF);
}
Ejemplo n.º 3
0
static void verify_existence(char **options, const char *name, int is_dir) {
  const char *path = get_option(options, name);
  if (!path_exists(path, is_dir)) {
    notify("Invalid path for %s: [%s]: (%s). Make sure that path is either "
           "absolute, or it is relative to mongoose executable.",
           name, path, strerror(errno));
  }
}
Ejemplo n.º 4
0
static inline int do_create(const char *path ,int mode)
{
  if(NO == path_exists(path))
    {
      return mkdir(path ,mode);
    }
  
  return PATH_IS_THERE;
}
Ejemplo n.º 5
0
int gmShellPlink::StageIn(const gmdArrayString& locfiles, pCSTR remdir, unsigned flags){
  gmdString tempdir, src, err;
  gmdArrayString srclist;

  if( StageIn_begin(NULL, remdir, flags) )
    return StageIn_end(NULL, remdir, flags);

  for(unsigned i=0; i<locfiles.GetCount(); i++) {
    gmdString lfile = locfiles[i];
    if( lfile.IsEmpty() ) continue;
    lfile.Replace("/", "\\");

    if( has_wildcards(lfile) ) {
      // List all files explicitly if lfile contains wildcards
      gmdArrayString filelist;
      unsigned nfiles = files_by_mask(lfile, filelist, flags);
      if(nfiles)
        for(unsigned k=0; k<nfiles; k++) srclist.Add(filelist[k]);
      else
        set_err(NO_INPUT_FILE, fmt("%s: no such files", (pCSTR)lfile.c_str()));
    }
    else if( path_exists(lfile, flags) )
      srclist.Add(lfile);
    else
      set_err(NO_INPUT_FILE, fmt("%s: no sich file or directory", (pCSTR)lfile.c_str()));
  }

  if( !srclist.IsEmpty() ) {
    if(flags & TEXT) {
      // Convert text files and store them in the temporary dir
      assert_no_recursive(flags);  // combination RECURSIVE & TEXT is not supported!
      tempdir = GetTempDir();
      //dos2unix(srclist, tempdir);
      conv_files(srclist, tempdir, dos2unix);
      src = tempdir + "\\*.*";
    } else {
      // prepare the space separated file list for PLINK
      for(unsigned i=0; i<srclist.GetCount(); i++)
        src += (i>0 ? "\" \"" : "") + srclist[i];
    }

    // Copy files
    if(!error_code) {
      gmdString args = (flags & RECURSIVE) ? "-r \"" : "\"";
      args += src + "\" \"" + userhost + ':' + rem_path_subst(remdir) + "\"";
      pscp_execute(args);
    }

    if( !tempdir.IsEmpty() ) remove_local(tempdir);

    if(!error_code && (flags & MOVE))  // custom move (not using StageIn_end)
      for(unsigned i=0; i<srclist.GetCount(); i++) RemoveLocal(srclist[i], flags);
  }

  return StageIn_end(NULL, remdir, flags);
}
Ejemplo n.º 6
0
CFStringRef copy_device_support_path(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    const char* home = getenv("HOME");
    CFStringRef path;
    bool found = false;

    path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@ (%@)"), home, version, build);
    found = path_exists(path);

    if (!found)
    {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)"), version, build);
        found = path_exists(path);
    }
    if (!found)
    {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@"), home, version);
        found = path_exists(path);
    }
    if (!found)
    {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@"), version);
        found = path_exists(path);
    }
    if (!found)
    {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@"), version);
        found = path_exists(path);
    }

    CFRelease(version);
    CFRelease(build);

    if (!found)
    {
        CFRelease(path);
        printf("[ !! ] Unable to locate DeviceSupport directory.\n");
        exit(1);
    }

    return path;
}
void path_delete(unsigned pathid)
{
    #ifdef DEBUG_MODE
    if (!path_exists(pathid)){
        show_error("Attempting to delete invalid path "+toString(pathid), false);
        return;
    }
    #endif
    delete enigma::pathstructarray[pathid];
}
Ejemplo n.º 8
0
static int add_configfs_base(void)
{
	int rv = 0;

	if (!path_exists("/sys/kernel/config")) {
		log_error("No /sys/kernel/config, is configfs loaded?");
		return -1;
	}

	if (!path_exists("/sys/kernel/config/dlm")) {
		log_error("No /sys/kernel/config/dlm, is the dlm loaded?");
		return -1;
	}

	if (!path_exists("/sys/kernel/config/dlm/cluster"))
		rv = create_path("/sys/kernel/config/dlm/cluster");

	return rv;
}
Ejemplo n.º 9
0
char*
avdInfo_getKernelPath( AvdInfo*  i )
{
    const char* imageName = _imageFileNames[ AVD_IMAGE_KERNEL ];

    char*  kernelPath = _avdInfo_getContentOrSdkFilePath(i, imageName);

    do {
        if (kernelPath || !i->inAndroidBuild)
            break;

        /* When in the Android build, look into the prebuilt directory
         * for our target architecture.
         */
        char temp[PATH_MAX], *p = temp, *end = p + sizeof(temp);
        const char* suffix = "";

        // If the target ABI is armeabi-v7a, then look for
        // kernel-qemu-armv7 instead of kernel-qemu in the prebuilt
        // directory.
        if (!strcmp(i->targetAbi, "armeabi-v7a")) {
            suffix = "-armv7";
        }

        p = bufprint(temp, end, "%s/kernel", i->androidOut);
        if (p < end && path_exists(temp)) {
            kernelPath = ASTRDUP(temp);
            break;
        }

        p = bufprint(temp, end, "%s/prebuilts/qemu-kernel/%s/kernel-qemu%s",
                     i->androidBuildRoot, i->targetArch, suffix);
        if (p >= end || !path_exists(temp)) {
            derror("bad workspace: cannot find prebuilt kernel in: %s", temp);
            exit(1);
        }
        kernelPath = ASTRDUP(temp);

    } while (0);

    return kernelPath;
}
AndroidPartitionType androidPartitionType_probeFile(const char* image_file) {
    if (!path_exists(image_file)) {
        return ANDROID_PARTITION_TYPE_UNKNOWN;
    }
    if (android_pathIsExt4PartitionImage(image_file)) {
        return ANDROID_PARTITION_TYPE_EXT4;
    }
    // Assume YAFFS2, since there is little way to be sure for now.
    // NOTE: An empty file is a valid Yaffs2 file!
    return ANDROID_PARTITION_TYPE_YAFFS2;
}
Ejemplo n.º 11
0
/* Resolve link target and either navigate inside directory link points to or
 * navigate to directory where target is located pointing cursor on
 * it (the follow_dirs flag controls behaviour). */
static void
follow_link(FileView *view, int follow_dirs)
{
	char *dir, *file;
	char full_path[PATH_MAX];
	char linkto[PATH_MAX + NAME_MAX];
	dir_entry_t *const entry = &curr_view->dir_entry[curr_view->list_pos];

	get_full_path_of(entry, sizeof(full_path), full_path);

	if(get_link_target_abs(full_path, entry->origin, linkto, sizeof(linkto)) != 0)
	{
		show_error_msg("Error", "Can't read link.");
		return;
	}

	if(!path_exists(linkto, DEREF))
	{
		show_error_msg("Broken Link",
				"Can't access link destination.  It might be broken.");
		return;
	}

	chosp(linkto);

	if(is_dir(linkto) && !follow_dirs)
	{
		dir = strdup(entry->name);
		file = NULL;
	}
	else
	{
		dir = strdup(linkto);
		remove_last_path_component(dir);

		file = get_last_path_component(linkto);
	}

	if(dir[0] != '\0')
	{
		navigate_to(view, dir);
	}

	if(file != NULL)
	{
		const int pos = find_file_pos_in_list(view, file);
		if(pos >= 0)
		{
			flist_set_pos(view, pos);
		}
	}

	free(dir);
}
Ejemplo n.º 12
0
static const char *
trap_path(const char *path)
{
    static char buf[PATH_MAX * 2];
    const char *prefix;
    size_t path_len;
    int check_exist = 0;

    /* do we need to trap this path? */
    if (path == NULL)
	return path;

    prefix = getenv("UMOCKDEV_DIR");
    if (prefix == NULL)
	return path;

    if (strncmp(path, "/dev/", 5) == 0 || strcmp(path, "/dev") == 0)
	check_exist = 1;
    else if (strncmp(path, "/sys/", 5) != 0 && strcmp(path, "/sys") != 0)
	return path;

    path_len = strlen(path);
    trap_path_prefix_len = strlen(prefix);
    if (path_len + trap_path_prefix_len >= sizeof(buf)) {
	errno = ENAMETOOLONG;
	return NULL;
    }

    /* test bed disabled? */
    strcpy(buf, prefix);
    strcpy(buf + trap_path_prefix_len, "/disabled");
    if (path_exists(buf) == 0)
	return path;

    strcpy(buf + trap_path_prefix_len, path);

    if (check_exist && path_exists(buf) < 0)
	return path;

    return buf;
}
Ejemplo n.º 13
0
CFStringRef copy_device_support_path(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    CFStringRef path_with_build = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)"), version, build);
    CFStringRef path_without_build = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@"), version);
    CFRelease(version);
    CFRelease(build);

    // they tack the build number on for beta builds
    // there is almost certainly a better way of doing this
    if (path_exists(path_with_build)) {
        CFRelease(path_without_build);
        return path_with_build;
    } else if (path_exists(path_without_build)) {
        CFRelease(path_with_build);
        return path_without_build;
    } else {
        printf("[ !! ] Unable to locate DeviceSupport directory.\n");
        exit(1);
    }
}
Ejemplo n.º 14
0
Archivo: archive.c Proyecto: Jinyan/git
static void parse_pathspec_arg(const char **pathspec,
		struct archiver_args *ar_args)
{
	ar_args->pathspec = pathspec = get_pathspec("", pathspec);
	if (pathspec) {
		while (*pathspec) {
			if (!path_exists(ar_args->tree, *pathspec))
				die("path not found: %s", *pathspec);
			pathspec++;
		}
	}
}
Ejemplo n.º 15
0
static char*
_getSdkImage( const char*  path, const char*  file )
{
    char  temp[MAX_PATH];
    char  *p = temp, *end = p + sizeof(temp);

    p = bufprint(temp, end, "%s/%s", path, file);
    if (p >= end || !path_exists(temp))
        return NULL;

    return android_strdup(temp);
}
Ejemplo n.º 16
0
/* check that a given directory contains a valid skin.
 * returns 1 on success, 0 on failure.
 */
static int
_checkSkinPath( const char*  skinPath )
{
    char  temp[MAX_PATH], *p=temp, *end=p+sizeof(temp);

    /* for now, if it has a 'layout' file, it is a valid skin path */
    p = bufprint(temp, end, "%s/layout", skinPath);
    if (p >= end || !path_exists(temp))
        return 0;

    return 1;
}
char* path_getBuildBootProp(const char* androidOut) {
    char temp[MAX_PATH], *p = temp, *end = p + sizeof(temp);
    p = bufprint(temp, end, "%s/boot.prop", androidOut);
    if (p >= end) {
        D("ANDROID_BUILD_OUT is too long: %s\n", androidOut);
        return NULL;
    }
    if (!path_exists(temp)) {
        D("Cannot find boot properties file: %s\n", temp);
        return NULL;
    }
    return ASTRDUP(temp);
}
Ejemplo n.º 18
0
bool path_read_text(const string& path, string& text)
{
	vector<uint8_t> binary;

	if(!path_exists(path) || !path_read_binary(path, binary))
		return false;

	const char *str = (const char*)&binary[0];
	size_t size = binary.size();
	text = string(str, size);

	return true;
}
Ejemplo n.º 19
0
int remove_file(char * path)
{
    if (path_exists(path))
    {
	    int ret = unlink(path);
	    if (ret == -1)
	    {
	        PERROR("unlink");
	        return -1;
	    }
	    return 0;
    }
    return 0;
}
Ejemplo n.º 20
0
Archivo: info.c Proyecto: cfillion/vifm
/* Performs conversions on files in trash required for partial backward
 * compatibility.  Returns newly allocated string that should be freed by the
 * caller. */
static char *
convert_old_trash_path(const char trash_path[])
{
	if(!is_path_absolute(trash_path) && is_dir_writable(cfg.trash_dir))
	{
		char *const full_path = format_str("%s/%s", cfg.trash_dir, trash_path);
		if(path_exists(full_path, DEREF))
		{
			return full_path;
		}
		free(full_path);
	}
	return strdup(trash_path);
}
Ejemplo n.º 21
0
CFStringRef copy_developer_disk_image_path(AMDeviceRef device) {
    CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
    CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
    const char *home = getenv("HOME");
    CFStringRef path;
    bool found = false;

	CFStringRef xcodeDevPath = copy_xcode_dev_path();

	path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@ (%@)/DeveloperDiskImage.dmg"), home, version, build);
	found = path_exists(path);

	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@/DeveloperDiskImage.dmg"), home, version);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/Latest/DeveloperDiskImage.dmg"), home);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)/DeveloperDiskImage.dmg"), xcodeDevPath, version, build);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/%@/DeveloperDiskImage.dmg"), xcodeDevPath, version);
		found = path_exists(path);
	}
	if (!found)
	{
		path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Platforms/iPhoneOS.platform/DeviceSupport/Latest/DeveloperDiskImage.dmg"), xcodeDevPath);
		found = path_exists(path);
	}

	CFRelease(version);
	CFRelease(build);
	CFRelease(xcodeDevPath);

    if (!found)
	{
		PRINT("[ !! ] Unable to locate DeviceSupport directory containing DeveloperDiskImage.dmg.\n");

		CFIndex pathLength = CFStringGetLength(path);
		char *buffer = calloc(pathLength + 1, sizeof(char));
		Boolean success = CFStringGetCString(path, buffer, pathLength + 1, kCFStringEncodingUTF8);
		CFRelease(path);

		if (success) PRINT("[ !! ] Last path checked: %s\n", buffer);
		exit(EXIT_FAILURE);
	}

	return path;
}
Ejemplo n.º 22
0
CFStringRef copy_xcode_path_for(CFStringRef subPath, CFStringRef search) {
    CFStringRef xcodeDevPath = copy_xcode_dev_path();
    CFStringRef path;
    bool found = false;
    const char* home = get_home();

    
    // Try using xcode-select --print-path
    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@/%@"), xcodeDevPath, subPath, search);
        found = path_exists(path);
    }
    // Try find `xcode-select --print-path` with search as a name pattern
    if (!found) {
        path = find_path(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@"), xcodeDevPath, subPath), search, CFSTR("-maxdepth 1"));
        found = CFStringGetLength(path) > 0 && path_exists(path);
    }
    // If not look in the default xcode location (xcode-select is sometimes wrong)
    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Applications/Xcode.app/Contents/Developer/%@&%@"), subPath, search);
        found = path_exists(path);
    }
    // If not look in the users home directory, Xcode can store device support stuff there
    if (!found) {
        path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/%@/%@"), home, subPath, search);
        found = path_exists(path);
    }
    
    CFRelease(xcodeDevPath);

    if (found) {
        return path;
    } else {
        CFRelease(path);
        return NULL;
    }
}
Ejemplo n.º 23
0
/* Check that there is a skin named 'skinName' listed from 'skinDirRoot'
 * this returns the full path of the skin directory (after alias expansions),
 * including the skin name, or NULL on failure.
 */
static char*
_checkSkinSkinsDir( const char*  skinDirRoot,
                    const char*  skinName )
{
    DirScanner*  scanner;
    char*        result;
    char         temp[MAX_PATH], *p = temp, *end = p + sizeof(temp);

    p = bufprint(temp, end, "%s/skins/%s", skinDirRoot, skinName);
    DD("Probing skin directory: %s", temp);
    if (p >= end || !path_exists(temp)) {
        DD("    ignore bad skin directory %s", temp);
        return NULL;
    }

    /* first, is this a normal skin directory ? */
    if (_checkSkinPath(temp)) {
        /* yes */
        DD("    found skin directory: %s", temp);
        return ASTRDUP(temp);
    }

    /* second, is it an alias to another skin ? */
    *p      = 0;
    result  = NULL;
    scanner = dirScanner_new(temp);
    if (scanner != NULL) {
        for (;;) {
            const char*  file = dirScanner_next(scanner);

            if (file == NULL)
                break;

            if (strncmp(file, "alias-", 6) || file[6] == 0)
                continue;

            p = bufprint(temp, end, "%s/skins/%s", skinDirRoot, file+6);
            if (p < end && _checkSkinPath(temp)) {
                /* yes, it's an alias */
                DD("    skin alias '%s' points to skin directory: %s",
                   file+6, temp);
                result = ASTRDUP(temp);
                break;
            }
        }
        dirScanner_free(scanner);
    }
    return result;
}
Ejemplo n.º 24
0
//-----------------------------------------------------------------------------
std::vector<std::string> get_subdirectories( const std::string& path ) {
  std::vector<std::string> subdirs;
  // validate that the path exists and that the path is a directory
  if( !path_exists( path ) || !is_directory( path ) ) return subdirs;

  std::vector<boost::filesystem::path> v;

  copy( boost::filesystem::directory_iterator(path), boost::filesystem::directory_iterator(), back_inserter(v) );

  for( std::vector<boost::filesystem::path>::iterator it = v.begin(); it != v.end(); it++ ) {
    std::string p = it->string();
    if( is_directory( p ) ) subdirs.push_back( p );
  }
  return subdirs;
}
Ejemplo n.º 25
0
static void
_forceAvdImagePath( AvdImageType  imageType,
                   const char*   path,
                   const char*   description,
                   int           required )
{
    if (path == NULL)
        return;

    if (required && !path_exists(path)) {
        derror("Cannot find %s image file: %s", description, path);
        exit(1);
    }
    android_avdParams->forcePaths[imageType] = path;
}
Ejemplo n.º 26
0
/* Tries to use $VIFM/vifmrc as configuration file.  Returns non-zero on
 * success, otherwise zero is returned. */
static int
try_vifm_vifmrc_for_vifmrc(void)
{
	LOG_FUNC_ENTER;

	char vifmrc[PATH_MAX + 1];
	const char *vifm = env_get(VIFM_EV);
	if(vifm == NULL || !is_dir(vifm))
		return 0;
	snprintf(vifmrc, sizeof(vifmrc), "%s/" VIFMRC, vifm);
	if(!path_exists(vifmrc, DEREF))
		return 0;
	env_set(MYVIFMRC_EV, vifmrc);
	return 1;
}
Ejemplo n.º 27
0
/* Look for a named file inside the AVD's content directory.
 * Returns NULL if it doesn't exist, or a strdup() copy otherwise.
 */
static char*
_avdInfo_getContentFilePath(AvdInfo*  i, const char* fileName)
{
    char temp[MAX_PATH], *p = temp, *end = p + sizeof(temp);

    p = bufprint(p, end, "%s/%s", i->contentPath, fileName);
    if (p >= end) {
        derror("can't access virtual device content directory");
        return NULL;
    }
    if (!path_exists(temp)) {
        return NULL;
    }
    return ASTRDUP(temp);
}
/* Return the path to the AVD's root configuration .ini file. it is located in
 * ~/.android/avd/<name>.ini or Windows equivalent
 *
 * This file contains the path to the AVD's content directory, which
 * includes its own config.ini.
 */
char*
path_getRootIniPath( const char*  avdName )
{
    char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);

    p = bufprint_config_path(temp, end);
    p = bufprint(p, end, PATH_SEP ANDROID_AVD_DIR PATH_SEP "%s.ini", avdName);
    if (p >= end) {
        return NULL;
    }
    if (!path_exists(temp)) {
        return NULL;
    }
    return ASTRDUP(temp);
}
Ejemplo n.º 29
0
int install_grub2(lickdir_t *lick) {
    char *grub_cfg_lick = unix_path(concat_strs(2, lick->drive, "/lickgrub.cfg"));
    if(!path_exists(grub_cfg_lick)) {
        char *grub_cfg_header = unix_path(concat_strs(2, lick->res, "/lickgrub.cfg"));
        if(!copy_file(grub_cfg_lick, grub_cfg_header)) {
            free(grub_cfg_lick);
            free(grub_cfg_header);
            if(!lick->err)
                lick->err = strdup2("Error writing to grub menu.");
            return 0;
        }
        free(grub_cfg_header);
    }
    free(grub_cfg_lick);
    return 1;
}
Ejemplo n.º 30
0
char*
avdInfo_getDynamicSkinPath( AvdInfo* i)
{
    char tmp[PATH_MAX];

    if (i->inAndroidBuild) {
        snprintf(tmp, sizeof(tmp), "%s/sdk/emulator/skins/dynamic/", i->androidBuildRoot);
    } else {
        snprintf(tmp, sizeof(tmp), "%s/tools/lib/emulator/skins/dynamic/", i->sdkRootPath);
    }

    if (!path_exists(tmp))
        return NULL;

    return ASTRDUP(tmp);
}