Example #1
0
static int
test_path_exists (void)
{
  char * const test_dir = create_test_dir (__FUNCTION__);
  tr_error * err = NULL;
  char * path1, * path2;

  path1 = tr_buildPath (test_dir, "a", NULL);
  path2 = tr_buildPath (test_dir, "b", NULL);

  /* Non-existent file does not exist */
  check (!tr_sys_path_exists (path1, &err));
  check (err == NULL);

  /* Create file and see that it exists */
  libtest_create_file_with_string_contents (path1, "test");
  check (tr_sys_path_exists (path1, &err));
  check (err == NULL);

  tr_sys_path_remove (path1, NULL);

  /* Create directory and see that it exists */
  tr_sys_dir_create (path1, 0, 0777, NULL);
  check (tr_sys_path_exists (path1, &err));
  check (err == NULL);

  tr_sys_path_remove (path1, NULL);

  if (create_symlink (path1, path2, false))
    {
      /* Non-existent file does not exist (via symlink) */
      check (!tr_sys_path_exists (path1, &err));
      check (err == NULL);

      /* Create file and see that it exists (via symlink) */
      libtest_create_file_with_string_contents (path2, "test");
      check (tr_sys_path_exists (path1, &err));
      check (err == NULL);

      tr_sys_path_remove (path2, NULL);

      /* Create directory and see that it exists (via symlink) */
      tr_sys_dir_create (path2, 0, 0777, NULL);
      check (tr_sys_path_exists (path1, &err));
      check (err == NULL);

      tr_sys_path_remove (path2, NULL);
      tr_sys_path_remove (path1, NULL);
    }
  else
    {
      fprintf (stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
    }

  tr_free (path2);
  tr_free (path1);

  tr_free (test_dir);
  return 0;
}
Example #2
0
void generate(int disk, int size)
{
	char path[PATH_MAX];
	char* file;

	snprintf(path, sizeof(path), "bench/disk%d/", disk);
	file = path + strlen(path);

	/* add a directory */
	*file++ = 'a' + rnd(2);
	*file = 0;

	/* create it */
	if (mkdir(path, 0777) != 0) {
		if (errno != EEXIST) {
			/* LCOV_EXCL_START */
			fprintf(stderr, "Error creating directory %s\n", path);
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}
	}

	*file++ = '/';

	while (1) {
		/* add a random file */
		rnd_name(file);

		/* skip some invalid file name, see http://en.wikipedia.org/wiki/Filename */
		if (strcmp(file, ".") == 0
			|| strcmp(file, "..") == 0
			|| strcmp(file, "prn") == 0
			|| strcmp(file, "con") == 0
			|| strcmp(file, "nul") == 0
			|| strcmp(file, "aux") == 0
			|| file[0] == ' '
			|| file[strlen(file)-1] == ' '
			|| file[strlen(file)-1] == '.'
		) {
			continue;
		}

		break;
	}

#ifndef WIN32 /* Windows XP doesn't support symlinks */
	if (rnd(32) == 0) {
		/* symlink */
		char linkto[PATH_MAX];

		rnd_name(linkto);

		create_symlink(path, linkto);
	} else
#endif
	{
		/* file */
		create_file(path, size);
	}
}
Example #3
0
static partition_result_t
create_udfs_vnodes(partition_private_t *partition_privatep)
{
	partition_result_t	partition_result;

	debug(2, "entering create_udfs_vnodes()\n");

	partition_result = PARTITION_SUCCESS;
	partition_result = create_pathnames(partition_privatep);
	if (partition_result == PARTITION_SUCCESS) {
		partition_result = create_volume(partition_privatep);
	}
	if (partition_result == PARTITION_SUCCESS) {
		partition_result = create_vvnodes(partition_privatep);
	}
	if (partition_result == PARTITION_SUCCESS) {
		correct_pathnames(partition_privatep);
	}
	if ((partition_result == PARTITION_SUCCESS) &&
		(partition_privatep->location == TOP)) {
		partition_result = create_symlink(partition_privatep);
	}
	debug(2, "leaving create_udfs_vnodes(), result code = %s\n",
		partition_result_codes[partition_result]);

	return (partition_result);
}
Example #4
0
int main (int argc, const char * argv[]) {
	
	print_cwd();

	// prepare source dir content
	{
		mkdir_source();
		chdir_source();

		create_file("myfile");
		create_symlink("myfile", "mylink");
		
		system("/usr/bin/SetFile -P -m 11/11/2011 mylink");
		system("/usr/bin/SetFile -m 01/01/2001 myfile");

		chdir_parent();
	}
	

	// copy content from source dir to target dir
	system("/bin/cp -Rp source target");
	

	// verify target dir content
	{
		int ok = 1;
		
		{
			struct timespec t1 = get_mtime("source/myfile");
			struct timespec t2 = get_mtime("target/myfile");
			if((t1.tv_sec != t2.tv_sec) || (t1.tv_nsec != t2.tv_nsec)) {
			    printf("TEST FAILED: timestamp on myfile differs\n");
				ok = 0;
			}
		}
		{
			struct timespec t1 = get_mtime("source/mylink");
			struct timespec t2 = get_mtime("target/mylink");
			if((t1.tv_sec != t2.tv_sec) || (t1.tv_nsec != t2.tv_nsec)) {
			    printf("TEST FAILED: timestamp on mylink differs\n");
				ok = 0;
			}
		}
		
		if(ok) {
			printf("TEST SUCCESS: mtime is copied correct, mtime is the same");
		}
	}

    return EXIT_SUCCESS;
}
Example #5
0
static int
test_path_resolve (void)
{
  char * const test_dir = create_test_dir (__FUNCTION__);
  tr_error * err = NULL;
  char * path1, * path2;

  path1 = tr_buildPath (test_dir, "a", NULL);
  path2 = tr_buildPath (test_dir, "b", NULL);

  libtest_create_file_with_string_contents (path1, "test");
  if (create_symlink (path2, path1, false))
    {
      char * tmp;

      tmp = tr_sys_path_resolve (path2, &err);
      check (tmp != NULL);
      check (err == NULL);
      check (path_contains_no_symlinks (tmp));
      tr_free (tmp);

      tr_sys_path_remove (path1, NULL);
      tr_sys_dir_create (path1, 0, 0755, NULL);

      tmp = tr_sys_path_resolve (path2, &err);
      check (tmp != NULL);
      check (err == NULL);
      check (path_contains_no_symlinks (tmp));
      tr_free (tmp);
    }
  else
    {
      fprintf (stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
    }

  tr_sys_path_remove (path2, NULL);
  tr_sys_path_remove (path1, NULL);

  tr_free (path2);
  tr_free (path1);

  tr_free (test_dir);
  return 0;
}
Example #6
0
static int
do_ln(void)
{
    int ret = -1;
    char name[MAX_FILE_NAME_LENGTH + 1];
    size_t size;
    char *src, *dst;

    if (read_all(STDIN, name, MAX_FILE_NAME_LENGTH) != MAX_FILE_NAME_LENGTH)
        return -1;
    name[MAX_FILE_NAME_LENGTH] = '\0';

    if (read_all(STDIN, &size, sizeof(size)) != sizeof(size))
        return -1;

    if (size > MAX_FILE_SIZE)
        return -1;

    if ((dst = calloc(size + 1)) == NULL)
        return -1;

    if (read_all(STDIN, dst, size) != size)
        goto free_dst;

    if ((src = get_path_from_dir(&vfs, pwd)) == NULL)
        goto free_dst;

    if ((src = append_to_path(src, name)) == NULL)
        goto free_src;

    if (create_symlink(&vfs, USER_UID, src, dst) != 0)
        goto free_src;

    ret = 0;

free_src:
    free(src);
free_dst:
    free(dst);
    return ret;
}
Example #7
0
bool UseVersion::update_sbin_symlink(string linkname, string newname)
{
	/**
	 * Get / set installation path of php version which user attends to switch.
	 */
	path sourcefile = installation_path;
	sourcefile.append("sbin/" + linkname);
	if (!exists(sourcefile))
		return false;
	/**
	 * Get / set destination of symbolic link
	 */
	path destlink = sbin_path;
	if (!exists(destlink))
		return false;

	newname.empty() ? destlink.append(linkname) : destlink.append(newname);

	/**
	 * We remove old link anyway since
	 * otherwise we can end up with links from different sources
	 */
	if (symbolic_link_exists(destlink))
		remove(destlink);

	/**
	 * Now link to previously used php version is removed
	 * we check can new one be made, so does PHP version user attends to
	 * use have such binary.
	 */
	if (!exists(sourcefile))
		return false;

	/**
	 * So source should be ok and old link removed so lets make new one
	 */
	create_symlink(sourcefile, destlink);
	return true;
}
Example #8
0
void change(const char* path, int size)
{
	struct stat st;

	if (!size)
		return;

	if (lstat(path, &st) != 0) {
		if (errno == ENOENT)
			return; /* it may be already deleted */
		/* LCOV_EXCL_START */
		fprintf(stderr, "Error accessing %s\n", path);
		exit(EXIT_FAILURE);
		/* LCOV_EXCL_STOP */
	}

	if (S_ISLNK(st.st_mode)) {
		/* symlink */
		if (rnd(2) == 0) {
			/* delete */
			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				fprintf(stderr, "Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}
		} else {
			/* recreate */
			char linkto[PATH_MAX];

			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				fprintf(stderr, "Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}

			rnd_name(linkto);

			create_symlink(path, linkto);
		}
	} else if (S_ISREG(st.st_mode)) {
		int r;

		r = rnd(4);

		if (r == 0) {
			/* write */
			writ(path, size, 0);
		} else if (r == 1) {
			/* append */
			append(path, size);
		} else if (r == 2) {
			/* truncate */
			truncat(path, size);
		} else {
			/* delete */
			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				fprintf(stderr, "Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}
		}
	}
}
Example #9
0
static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
			     DIR *dir)
{
	size_t path_baselen = path->len;
	size_t template_baselen = template_path->len;
	struct dirent *de;

	/* Note: if ".git/hooks" file exists in the repository being
	 * re-initialized, /etc/core-git/templates/hooks/update would
	 * cause "git init" to fail here.  I think this is sane but
	 * it means that the set of templates we ship by default, along
	 * with the way the namespace under .git/ is organized, should
	 * be really carefully chosen.
	 */
	safe_create_dir(path->buf, 1);
	while ((de = readdir(dir)) != NULL) {
		struct stat st_git, st_template;
		int exists = 0;

		strbuf_setlen(path, path_baselen);
		strbuf_setlen(template_path, template_baselen);

		if (de->d_name[0] == '.')
			continue;
		strbuf_addstr(path, de->d_name);
		strbuf_addstr(template_path, de->d_name);
		if (lstat(path->buf, &st_git)) {
			if (errno != ENOENT)
				die_errno(_("cannot stat '%s'"), path->buf);
		}
		else
			exists = 1;

		if (lstat(template_path->buf, &st_template))
			die_errno(_("cannot stat template '%s'"), template_path->buf);

		if (S_ISDIR(st_template.st_mode)) {
			DIR *subdir = opendir(template_path->buf);
			if (!subdir)
				die_errno(_("cannot opendir '%s'"), template_path->buf);
			strbuf_addch(path, '/');
			strbuf_addch(template_path, '/');
			copy_templates_1(path, template_path, subdir);
			closedir(subdir);
		}
		else if (exists)
			continue;
		else if (S_ISLNK(st_template.st_mode)) {
			struct strbuf lnk = STRBUF_INIT;
			if (strbuf_readlink(&lnk, template_path->buf,
					    st_template.st_size) < 0)
				die_errno(_("cannot readlink '%s'"), template_path->buf);
			if (create_symlink(NULL, lnk.buf, path->buf))
				die_errno(_("cannot symlink '%s' '%s'"),
					  lnk.buf, path->buf);
			strbuf_release(&lnk);
		}
		else if (S_ISREG(st_template.st_mode)) {
			if (copy_file(path->buf, template_path->buf, st_template.st_mode))
				die_errno(_("cannot copy '%s' to '%s'"),
					  template_path->buf, path->buf);
		}
		else
			error(_("ignoring template %s"), template_path->buf);
	}
}
Example #10
0
static int create_default_files(const char *template_path,
				const char *original_git_dir)
{
	struct stat st1;
	struct strbuf buf = STRBUF_INIT;
	char *path;
	char repo_version_string[10];
	char junk[2];
	int reinit;
	int filemode;
	struct strbuf err = STRBUF_INIT;

	/* Just look for `init.templatedir` */
	git_config(git_init_db_config, NULL);

	/*
	 * First copy the templates -- we might have the default
	 * config file there, in which case we would want to read
	 * from it after installing.
	 *
	 * Before reading that config, we also need to clear out any cached
	 * values (since we've just potentially changed what's available on
	 * disk).
	 */
	copy_templates(template_path);
	git_config_clear();
	reset_shared_repository();
	git_config(git_default_config, NULL);

	/*
	 * We must make sure command-line options continue to override any
	 * values we might have just re-read from the config.
	 */
	is_bare_repository_cfg = init_is_bare_repository;
	if (init_shared_repository != -1)
		set_shared_repository(init_shared_repository);

	/*
	 * We would have created the above under user's umask -- under
	 * shared-repository settings, we would need to fix them up.
	 */
	if (get_shared_repository()) {
		adjust_shared_perm(get_git_dir());
	}

	/*
	 * We need to create a "refs" dir in any case so that older
	 * versions of git can tell that this is a repository.
	 */
	safe_create_dir(git_path("refs"), 1);
	adjust_shared_perm(git_path("refs"));

	if (refs_init_db(&err))
		die("failed to set up refs db: %s", err.buf);

	/*
	 * Create the default symlink from ".git/HEAD" to the "master"
	 * branch, if it does not exist yet.
	 */
	path = git_path_buf(&buf, "HEAD");
	reinit = (!access(path, R_OK)
		  || readlink(path, junk, sizeof(junk)-1) != -1);
	if (!reinit) {
		if (create_symref("HEAD", "refs/heads/master", NULL) < 0)
			exit(1);
	}

	/* This forces creation of new config file */
	xsnprintf(repo_version_string, sizeof(repo_version_string),
		  "%d", GIT_REPO_VERSION);
	git_config_set("core.repositoryformatversion", repo_version_string);

	/* Check filemode trustability */
	path = git_path_buf(&buf, "config");
	filemode = TEST_FILEMODE;
	if (TEST_FILEMODE && !lstat(path, &st1)) {
		struct stat st2;
		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
				!lstat(path, &st2) &&
				st1.st_mode != st2.st_mode &&
				!chmod(path, st1.st_mode));
		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
			filemode = 0;
	}
	git_config_set("core.filemode", filemode ? "true" : "false");

	if (is_bare_repository())
		git_config_set("core.bare", "true");
	else {
		const char *work_tree = get_git_work_tree();
		git_config_set("core.bare", "false");
		/* allow template config file to override the default */
		if (log_all_ref_updates == LOG_REFS_UNSET)
			git_config_set("core.logallrefupdates", "true");
		if (needs_work_tree_config(original_git_dir, work_tree))
			git_config_set("core.worktree", work_tree);
	}

	if (!reinit) {
		/* Check if symlink is supported in the work tree */
		path = git_path_buf(&buf, "tXXXXXX");
		if (!close(xmkstemp(path)) &&
		    !unlink(path) &&
		    !create_symlink(NULL, "testing", path) &&
		    !lstat(path, &st1) &&
		    S_ISLNK(st1.st_mode))
			unlink(path); /* good */
		else
			git_config_set("core.symlinks", "false");

		/* Check if the filesystem is case-insensitive */
		path = git_path_buf(&buf, "CoNfIg");
		if (!access(path, F_OK))
			git_config_set("core.ignorecase", "true");
		probe_utf8_pathname_composition();
	}

	strbuf_release(&buf);
	return reinit;
}
Example #11
0
void Def::
write_ctype (std::string dir_name)
{
    // dir_name cannot be empty
    assert (!dir_name.empty());

    if (ctype_filename_.empty ()) {
        ctype_filename_ = dir_name + _RWSTD_PATH_SEP + lc_name;
        ctype_symlink_ = false;
    }

    // if a CTYPE section was not found or ctype info has been already written
    // in the database
    if (ctype_def_found_ && !ctype_written_) {      

        issue_diag (I_OPENWR, false, 0,
                    "writing %s\n", ctype_filename_.c_str ());

        std::ofstream out (ctype_filename_.c_str(), std::ios::binary);
        out.exceptions (std::ios::failbit | std::ios::badbit);
        
        // calculate the offsets for the wchar_t arrays
        ctype_out_.wtoupper_off = 0;
        ctype_out_.wtolower_off = unsigned (ctype_out_.wtoupper_off 
            + upper_.size() * sizeof (_RW::__rw_upper_elm));
        ctype_out_.wmask_off = unsigned (ctype_out_.wtolower_off
            + lower_.size() * sizeof (_RW::__rw_lower_elm));
        ctype_out_.wmask_s = unsigned (mask_.size());

        // calculate the offsets for the codeset name string and character
        // map name string
        ctype_out_.codeset_off = unsigned (ctype_out_.wmask_off
            + mask_.size() * sizeof (_RW::__rw_mask_elm));
        ctype_out_.charmap_off = unsigned (ctype_out_.codeset_off 
            + charmap_.get_code_set_name().size() + 1);
       
        ctype_out_.mb_cur_max = charmap_.get_mb_cur_max();
        std::size_t i;

        for (i = 0; i <= UCHAR_MAX; i++) {
            if(0 == ctype_out_.toupper_tab[i])
                ctype_out_.toupper_tab[i] = (char)i;
            if(0 == ctype_out_.tolower_tab[i])
                ctype_out_.tolower_tab[i] = (char)i;
        }
        
        // write the ctype_out structure
        out.write ((char*)&ctype_out_, sizeof(ctype_out_));

        // print out the wide character arrays
        for(upper_iter u_pos = upper_.begin(); u_pos != upper_.end(); u_pos++){
            _RW::__rw_upper_elm elm = {u_pos->first, u_pos->second};
            out.write((char*)&elm, sizeof(elm));
        }
        for(lower_iter l_pos = lower_.begin(); l_pos != lower_.end(); l_pos++){
            _RW::__rw_lower_elm elm = {l_pos->first, l_pos->second};
            out.write((char*)&elm, sizeof(elm));
        }
        for(mask_iter m_pos = mask_.begin(); m_pos != mask_.end(); m_pos++){
            _RW::__rw_mask_elm elm = {m_pos->first, m_pos->second};
            out.write((char*)&elm, sizeof(elm));
        }

        // write the code_set_name string and charmap string
        out << charmap_.get_code_set_name() << std::ends
            << charmap_.get_charmap_name() << std::ends;
    
    }

#if !defined (_WIN32) && !defined (__CYGWIN__)
    
    if (ctype_symlink_) {

        std::string xname (ctype_filename_);
        if (xname [0] != _RWSTD_PATH_SEP) {
            xname = std::string (".."); 
            xname += _RWSTD_PATH_SEP;
            xname += ctype_filename_.substr (
                ctype_filename_.rfind (_RWSTD_PATH_SEP) + 1,
                ctype_filename_.size ());
        }

        std::string sname (lc_name);
        create_symlink (output_name_, xname, sname);
        return;
    }

#endif  // !_WIN32 && !__CYGWIN__

}
Example #12
0
static void
create_locale (std::string std_src,
               std::string std_cmap, 
               std::string outdir,
               std::string std_locale, 
               bool force_output, bool use_ucs,
               bool no_position, bool link_aliases)
{
    // extract the names of the locale and of the codeset
    std::string lname (std_src);
    std::string cname (std_cmap);

    if (lname.rfind(_RWSTD_PATH_SEP) != std::string::npos)
        lname = lname.substr(lname.rfind(_RWSTD_PATH_SEP) + 1, lname.size());

    if (cname.rfind(_RWSTD_PATH_SEP) != std::string::npos)
        cname = cname.substr(cname.rfind(_RWSTD_PATH_SEP) + 1, cname.size());

    if (lname.find('.') != std::string::npos)
        lname = lname.substr(0, lname.find('.'));
    if (cname.find('.') != std::string::npos)
        cname = cname.substr(0, cname.find('.'));
    
    // the vector of corresponding C locales
    StringVector C_locales;
#ifndef _MSC_VER
    get_same_encoding_C_locale (lname, cname, C_locales);
#endif  // _MSC_VER

    // C library locale using same encoding
    std::string enc_C_locale;

#ifdef _RWSTD_NO_ISO_10646_WCHAR_T
    // the encoding C locale
    enc_C_locale = get_C_encoding_locale (cname);

    // platforms with locale dependant wchar_t encodings need the current 
    // C locale to be set.  If there is no C locale with the same name
    // or that uses the same encoding as the locale we are creating 
    // issue warning
    if (enc_C_locale.empty ()) {
        issue_diag (W_COMPAT, false, 0, "no compatible locale found\n");
    } else
        std::setlocale (LC_ALL, enc_C_locale.c_str ());
        
#endif   // _RWSTD_NO_ISO_10646_WCHAR_T

    // if no charmap is present assume ISO-8859-1
    if (std_cmap.empty ())
        std_cmap = "ISO-8859-1";
        
    // retrieve UTF-8 encoding aliases
    std::string utf8_cname("UTF-8");
    StringVector utf8_aliases;
    get_cname_aliases (utf8_cname, utf8_aliases);

    // is it a UTF-8 encoded locale?
    bool is_utf8 = false;
    StringVector::iterator pos = utf8_aliases.begin();
    for (; pos != utf8_aliases.end (); pos++)
        if (ci_compare (cname, *pos) == 0) {
            is_utf8 = true;
            break;
        }

    // retrieve the charmap/codeset object 
    Charmap* charmap_p = 0;        
    std::vector <Charmap*>::iterator charmaps_it = charmaps.begin();
    for (; charmaps_it != charmaps.end(); charmaps_it++){
        if ((*charmaps_it)->get_full_charmap_name() == std_cmap) {
            charmap_p = *charmaps_it;
            break;
        }
    }

    // if none found, create one and parse the corresponding file
    if (0 == charmap_p) {

        issue_diag (I_STAGE, false, 0,
                    "processing character set description file %s\n",
                    std_cmap.c_str ());

        charmap_p = new Charmap (enc_C_locale.c_str (),
                                 std_cmap.c_str (), 
                                 is_utf8, true, true, use_ucs);
        charmaps.push_back (charmap_p);
    }

    // parse the source definition files
    bool def_error = false;

    issue_diag (I_STAGE, false, 0,
                "processing locale definition file %s\n", std_src.c_str ());

    Def def (std_src.c_str (), (outdir + std_locale).c_str (),
             *charmap_p, no_position);

    try {
        // try to parse the input files
        def.process_input ();
    }
    catch (...) {
        def_error = true;
    }

    // create the locale directory
    std::string locale_dir (outdir + std_locale);

    makedir (locale_dir.c_str ());

    if (def_error) {
        // write out the codecvt database and exit if parsing failed
        def.write_codecvt (locale_dir);
        throw loc_exception ("abort.");
    }

    // no output when it hasn't been forced and warnings were present
    if (!force_output && def.warnings_occurred_) {
        std::cerr << "Warnings occurred - No output produced\n";
        return;
    }

    // and write out the locale categories data
    issue_diag (I_STAGE, false, 0, "generating LC_CTYPE database\n");
    def.write_ctype (locale_dir);

    issue_diag (I_STAGE, false, 0, "generating codeset database\n");
    def.write_codecvt (locale_dir);

    issue_diag (I_STAGE, false, 0, "generating LC_MONETARY database\n");
    def.write_monetary (locale_dir);

    issue_diag (I_STAGE, false, 0, "generating LC_NUMERIC database\n");
    def.write_numeric (locale_dir);

    issue_diag (I_STAGE, false, 0, "generating LC_TIME database\n");
    def.write_time (locale_dir);

    issue_diag (I_STAGE, false, 0, "generating LC_COLLATE database\n");
    def.write_collate (locale_dir);

#ifndef _MSC_VER

    issue_diag (I_STAGE, false, 0, "generating LC_MESSAGES database\n");
    def.write_messages (locale_dir);

#endif  // _MSC_VER

    // no C library locales equivalents 
    if (C_locales.empty ())
        return;

#if !defined (_MSC_VER)

    if (link_aliases == false)
        return;

    // some corresponding C lib locale names where found for this name
    StringVector::iterator it = C_locales.begin ();
    for (; it != C_locales.end (); it++) {
        // check if the name actually exists
        if (*it == std_locale)
            continue;

        // set a symlink with the name of the C lib locale
        // pointing to our locale database
        create_symlink (outdir, std_locale, *it);
    }
#endif  // _MSC_VER
}
Example #13
0
static int
test_path_is_same (void)
{
  char * const test_dir = create_test_dir (__FUNCTION__);
  tr_error * err = NULL;
  char * path1, * path2, * path3;

  path1 = tr_buildPath (test_dir, "a", NULL);
  path2 = tr_buildPath (test_dir, "b", NULL);
  path3 = tr_buildPath (path2, "c", NULL);

  /* Two non-existent files are not the same */
  check (!tr_sys_path_is_same (path1, path1, &err));
  check (err == NULL);
  check (!tr_sys_path_is_same (path1, path2, &err));
  check (err == NULL);

  /* Two same files are the same */
  libtest_create_file_with_string_contents (path1, "test");
  check (tr_sys_path_is_same (path1, path1, &err));
  check (err == NULL);

  /* Existent and non-existent files are not the same */
  check (!tr_sys_path_is_same (path1, path2, &err));
  check (err == NULL);
  check (!tr_sys_path_is_same (path2, path1, &err));
  check (err == NULL);

  /* Two separate files (even with same content) are not the same */
  libtest_create_file_with_string_contents (path2, "test");
  check (!tr_sys_path_is_same (path1, path2, &err));
  check (err == NULL);

  tr_sys_path_remove (path1, NULL);

  /* Two same directories are the same */
  tr_sys_dir_create (path1, 0, 0777, NULL);
  check (tr_sys_path_is_same (path1, path1, &err));
  check (err == NULL);

  /* File and directory are not the same */
  check (!tr_sys_path_is_same (path1, path2, &err));
  check (err == NULL);
  check (!tr_sys_path_is_same (path2, path1, &err));
  check (err == NULL);

  tr_sys_path_remove (path2, NULL);

  /* Two separate directories are not the same */
  tr_sys_dir_create (path2, 0, 0777, NULL);
  check (!tr_sys_path_is_same (path1, path2, &err));
  check (err == NULL);

  tr_sys_path_remove (path1, NULL);
  tr_sys_path_remove (path2, NULL);

  if (create_symlink (path1, ".", true))
    {
      /* Directory and symlink pointing to it are the same */
      check (tr_sys_path_is_same (path1, test_dir, &err));
      check (err == NULL);
      check (tr_sys_path_is_same (test_dir, path1, &err));
      check (err == NULL);

      /* Non-existent file and symlink are not the same */
      check (!tr_sys_path_is_same (path1, path2, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path2, path1, &err));
      check (err == NULL);

      /* Symlinks pointing to different directories are not the same */
      create_symlink (path2, "..", true);
      check (!tr_sys_path_is_same (path1, path2, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path2, path1, &err));
      check (err == NULL);

      tr_sys_path_remove (path2, NULL);

      /* Symlinks pointing to same directory are the same */
      create_symlink (path2, ".", true);
      check (tr_sys_path_is_same (path1, path2, &err));
      check (err == NULL);

      tr_sys_path_remove (path2, NULL);

      /* Directory and symlink pointing to another directory are not the same */
      tr_sys_dir_create (path2, 0, 0777, NULL);
      check (!tr_sys_path_is_same (path1, path2, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path2, path1, &err));
      check (err == NULL);

      /* Symlinks pointing to same directory are the same */
      create_symlink (path3, "..", true);
      check (tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);

      tr_sys_path_remove (path1, NULL);

      /* File and symlink pointing to directory are not the same */
      libtest_create_file_with_string_contents (path1, "test");
      check (!tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path3, path1, &err));
      check (err == NULL);

      tr_sys_path_remove (path3, NULL);

      /* File and symlink pointing to same file are the same */
      create_symlink (path3, path1, false);
      check (tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);
      check (tr_sys_path_is_same (path3, path1, &err));
      check (err == NULL);

      /* Symlinks pointing to non-existent files are not the same */
      tr_sys_path_remove (path1, NULL);
      create_symlink (path1, "missing", false);
      tr_sys_path_remove (path3, NULL);
      create_symlink (path3, "missing", false);
      check (!tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path3, path1, &err));
      check (err == NULL);

      tr_sys_path_remove (path3, NULL);

      /* Symlinks pointing to same non-existent file are not the same */
      create_symlink (path3, ".." NATIVE_PATH_SEP "missing", false);
      check (!tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path3, path1, &err));
      check (err == NULL);

      /* Non-existent file and symlink pointing to non-existent file are not the same */
      tr_sys_path_remove (path3, NULL);
      check (!tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path3, path1, &err));
      check (err == NULL);

      tr_sys_path_remove (path2, NULL);
      tr_sys_path_remove (path1, NULL);
    }
  else
    {
      fprintf (stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
    }

  tr_free (path3);
  path3 = tr_buildPath (test_dir, "c", NULL);

  libtest_create_file_with_string_contents (path1, "test");

  if (create_hardlink (path2, path1))
    {
      /* File and hardlink to it are the same */
      check (tr_sys_path_is_same (path1, path2, &err));
      check (err == NULL);

      /* Two hardlinks to the same file are the same */
      create_hardlink (path3, path2);
      check (tr_sys_path_is_same (path2, path3, &err));
      check (err == NULL);
      check (tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);

      tr_sys_path_remove (path2, NULL);

      check (tr_sys_path_is_same (path1, path3, &err));
      check (err == NULL);

      tr_sys_path_remove (path3, NULL);

      /* File and hardlink to another file are not the same */
      libtest_create_file_with_string_contents (path3, "test");
      create_hardlink (path2, path3);
      check (!tr_sys_path_is_same (path1, path2, &err));
      check (err == NULL);
      check (!tr_sys_path_is_same (path2, path1, &err));
      check (err == NULL);

      tr_sys_path_remove (path3, NULL);
      tr_sys_path_remove (path2, NULL);
    }
  else
    {
      fprintf (stderr, "WARNING: [%s] unable to run hardlink tests\n", __FUNCTION__);
    }

  if (create_symlink (path2, path1, false) && create_hardlink (path3, path1))
    {
      check (tr_sys_path_is_same (path2, path3, &err));
      check (err == NULL);
    }
  else
    {
      fprintf (stderr, "WARNING: [%s] unable to run combined symlink and hardlink tests\n", __FUNCTION__);
    }

  tr_sys_path_remove (path3, NULL);
  tr_sys_path_remove (path2, NULL);
  tr_sys_path_remove (path1, NULL);

  tr_free (path3);
  tr_free (path2);
  tr_free (path1);

  tr_free (test_dir);
  return 0;
}
Example #14
0
static int
test_get_info (void)
{
  char * const test_dir = create_test_dir (__FUNCTION__);
  tr_sys_path_info info;
  tr_sys_file_t fd;
  tr_error * err = NULL;
  char * path1, * path2;
  time_t t;

  path1 = tr_buildPath (test_dir, "a", NULL);
  path2 = tr_buildPath (test_dir, "b", NULL);

  /* Can't get info of non-existent file/directory */
  check (!tr_sys_path_get_info (path1, 0, &info, &err));
  check (err != NULL);
  tr_error_clear (&err);

  t = time (NULL);
  libtest_create_file_with_string_contents (path1, "test");

  /* Good file info */
  clear_path_info (&info);
  check (tr_sys_path_get_info (path1, 0, &info, &err));
  check (err == NULL);
  check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
  check_int_eq (4, info.size);
  check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));

  /* Good file info (by handle) */
  fd = tr_sys_file_open (path1, TR_SYS_FILE_READ, 0, NULL);
  clear_path_info (&info);
  check (tr_sys_file_get_info (fd, &info, &err));
  check (err == NULL);
  check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
  check_int_eq (4, info.size);
  check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
  tr_sys_file_close (fd, NULL);

  tr_sys_path_remove (path1, NULL);

  /* Good directory info */
  t = time (NULL);
  tr_sys_dir_create (path1, 0, 0777, NULL);
  clear_path_info (&info);
  check (tr_sys_path_get_info (path1, 0, &info, &err));
  check (err == NULL);
  check_int_eq (TR_SYS_PATH_IS_DIRECTORY, info.type);
  check (info.size != (uint64_t) -1);
  check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
  tr_sys_path_remove (path1, NULL);

  if (create_symlink (path1, path2, false))
    {
      /* Can't get info of non-existent file/directory */
      check (!tr_sys_path_get_info (path1, 0, &info, &err));
      check (err != NULL);
      tr_error_clear (&err);

      t = time (NULL);
      libtest_create_file_with_string_contents (path2, "test");

      /* Good file info */
      clear_path_info (&info);
      check (tr_sys_path_get_info (path1, 0, &info, &err));
      check (err == NULL);
      check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
      check_int_eq (4, info.size);
      check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));

      /* Good file info (by handle) */
      fd = tr_sys_file_open (path1, TR_SYS_FILE_READ, 0, NULL);
      clear_path_info (&info);
      check (tr_sys_file_get_info (fd, &info, &err));
      check (err == NULL);
      check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
      check_int_eq (4, info.size);
      check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
      tr_sys_file_close (fd, NULL);

      tr_sys_path_remove (path2, NULL);

      /* Good directory info */
      t = time (NULL);
      tr_sys_dir_create (path2, 0, 0777, NULL);
      clear_path_info (&info);
      check (tr_sys_path_get_info (path1, 0, &info, &err));
      check (err == NULL);
      check_int_eq (TR_SYS_PATH_IS_DIRECTORY, info.type);
      check (info.size != (uint64_t) -1);
      check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));

      tr_sys_path_remove (path2, NULL);
      tr_sys_path_remove (path1, NULL);
    }
  else
    {
      fprintf (stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
    }

  tr_free (path2);
  tr_free (path1);

  tr_free (test_dir);
  return 0;
}