Beispiel #1
0
const char *
file_extension_c(const char *filename)
{
    const char *base = file_basename_c(filename);

    return strrchr(base, '.');
}
Beispiel #2
0
char *
file_dirname(const char *filename)
{
    const char *base;

    if ((base = file_basename_c(filename)) == filename)
	return g_strdup(".");
    return g_strndup(filename, (base - filename - 1));
}
Beispiel #3
0
static gboolean
copy_one(const char *filename, void *userdata)
{
    copy_task_t *ct = (copy_task_t *)userdata;
    const char *fromfile;
    string_var tofile, mappedfile;
    
    // TODO: WTF
        
    /* construct the target filename */
    if (ct->flatten_)
    	fromfile = file_basename_c(filename);
    else
    	fromfile = filename;
	
    if (ct->tofile_ != 0)
    	tofile = ct->expand(ct->tofile_);
    else if (ct->exp_todir_ != 0)
	tofile = g_strconcat(ct->exp_todir_, "/", filename, 0);
    else
    {
	ct->result_ = FALSE; 	/* failed */
	return FALSE;	    	/* stop iteration */
    }
    if ((mappedfile = ct->mapper_->map(tofile)) == 0)
	return TRUE;	    	/* keep going */
        
    log::infof("%s -> %s\n", filename, mappedfile.data());
	
    /* TODO: apply proj->basedir */

    if (file_is_directory(filename) == 0)
    {
    	int r;
	unsigned ncopied = ct->ncopied_;
	
	r = file_apply_children(filename, copy_one, userdata);
	
	if (r < 0)
	{
	    log::perror(filename);
	}
	else if (ncopied == ct->ncopied_ && ct->include_empty_dirs_)
	{
	    /* no files copied underneath this directory -- it must be empty */
	    /* TODO: sensible mode from original directory */
	    /* TODO: control uid,gid */
	    if (file_build_tree(mappedfile, 0755))
	    {
		log::perror(filename);
		ct->result_ = FALSE;
    	    }
	}
    }
    else
    {
	if (!do_copy_file(filename, mappedfile))
	    ct->result_ = FALSE;
    }
        
    return ct->result_;    /* keep going if we didn't fail */
}