Exemplo n.º 1
0
void test_create_xdg_dirs_when_dotlocal_and_dotconfig_have_not_been_created(void **param)
{
	//set temporary directory as HOME in order to ensure that .local and .config do not exist
	char *previous_home_dir = strdup(getenv("HOME"));
	char temp_home_dir[] = "/tmp/flybyXXXXXXXX";
	mkdtemp(temp_home_dir);
	setenv("HOME", temp_home_dir, 1);
	assert_true(directory_exists(temp_home_dir));

	//ensure XDG_*_HOME are empty
	setenv("XDG_DATA_HOME", "", 1);
	setenv("XDG_CONFIG_HOME", "", 1);

	char *data_home_path = xdg_data_home();
	char *config_home_path = xdg_config_home();
	assert_false(directory_exists(data_home_path));
	assert_false(directory_exists(config_home_path));

	//ensure that XDG_DATA_HOME and XDG_CONFIG_HOME are as expected
	char *expected_data_home_path = add_to_path(temp_home_dir, DEFAULT_XDG_DATA_HOME);
	char *expected_config_home_path = add_to_path(temp_home_dir, DEFAULT_XDG_CONFIG_HOME);
	assert_string_equal(data_home_path, expected_data_home_path);
	assert_string_equal(config_home_path, expected_config_home_path);

	free(expected_data_home_path);
	free(expected_config_home_path);

	//test directory creation
	test_create_xdg_dirs();

	//revert HOME variable
	setenv("HOME", previous_home_dir, 1);
	free(previous_home_dir);

	//clean up directories
	char *data_home_base_path = add_to_path(temp_home_dir, DEFAULT_XDG_DATA_HOME_BASE); //corresponds to (...)/.local
	rmdir(data_home_path);
	rmdir(data_home_base_path);
	rmdir(config_home_path);
	rmdir(temp_home_dir);
	assert_false(directory_exists(temp_home_dir));

	free(data_home_base_path);
	free(data_home_path);
	free(config_home_path);
}
Exemplo n.º 2
0
void TempDir::attach(const string& path)
{
  if (!m_path.empty())
    remove_directory(m_path);

  ASSERT(directory_exists(path));
  m_path = path;
}
Exemplo n.º 3
0
 void create_directory(std::string dir)
 {
     if (!directory_exists(dir)) {
         if (mkdir(dir.c_str(), 0777) == -1) {
             LOG(FATAL) << "could not create directory";
         }
     }
 }
TEST(adb_utils, directory_exists) {
#ifdef _WIN32
  char profiles_dir[MAX_PATH];
  DWORD cch = arraysize(profiles_dir);

  // On typical Windows 7, returns C:\Users
  ASSERT_TRUE(GetProfilesDirectory(profiles_dir, &cch));

  ASSERT_TRUE(directory_exists(profiles_dir));

  // On modern (English?) Windows, this is a directory symbolic link to
  // C:\ProgramData. Symbolic links are rare on Windows and the user requires
  // a special permission (by default granted to Administrative users) to
  // create symbolic links.
  ASSERT_FALSE(directory_exists(subdir(profiles_dir, "All Users")));

  // On modern (English?) Windows, this is a directory junction to
  // C:\Users\Default. Junctions are used throughout user profile directories
  // for backwards compatibility and they don't require any special permissions
  // to create.
  ASSERT_FALSE(directory_exists(subdir(profiles_dir, "Default User")));

  ASSERT_FALSE(directory_exists(subdir(profiles_dir, "does-not-exist")));
#else
  ASSERT_TRUE(directory_exists("/proc"));
  ASSERT_FALSE(directory_exists("/proc/self")); // Symbolic link.
  ASSERT_FALSE(directory_exists("/proc/does-not-exist"));
#endif
}
Exemplo n.º 5
0
static void assert_cache_directory_existence()
{
	// We do not consider the cache directory's mode yet. Must be considerd regarding it later.
	if(!directory_exists(CACHE_DIRECTORY_PATH))
	{
		if(!make_directory(CACHE_DIRECTORY_PATH, CACHE_DIRECTORY_PERMISSION_MODE))
			int_error("Creating a cache directory failed");
	}
}
Exemplo n.º 6
0
bool confirm_directory( const std::string &base, const std::string &sub )
{
	if ( !directory_exists( base ) )
#ifdef SFML_SYSTEM_WINDOWS
		mkdir( base.c_str() );
#else
		mkdir( base.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH  );
#endif // SFML_SYSTEM_WINDOWS

	if ( (!sub.empty()) && (!directory_exists( base + sub )) )
#ifdef SFML_SYSTEM_WINDOWS
		mkdir( (base + sub).c_str() );
#else
		mkdir( (base + sub).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH  );
#endif // SFML_SYSTEM_WINDOWS

	return true;
}
Exemplo n.º 7
0
Arquivo: file.c Projeto: ekiru/fslabel
int ensure_directory(char *directory) {
	if (!directory_exists(directory)) {
		if (mkdir(directory, 0777) == -1) {
			directory_could_not_be_created_error();
			return -1;
		}
	}
	return 0;
}
void PoseEstimator::init()
{
	if (!directory_exists(pose_database_path))
		create_directory(pose_database_path);

	load();

	console_log("pose estimator initialized");
}
Exemplo n.º 9
0
/* =============== GPL HEADER =====================
 * TuxStrings.c is part of TuxDroidServer
 * Copyleft (C) 2012 - Joel Matteotti <joel _DOT_ matteotti _AT_ free _DOT_ fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 * ====================================================
*/

#include <stdlib.h>
#include <unistd.h>

#include <unity.h>
#include "TuxUtils.h"

#define SHELL_COMMAND_LEN 256
#define PATH_LEN 256
char old_cwd[PATH_LEN];

void _saveCWD();
void _restoreCWD();
void _createTemporaryDirectory(char *directory_path);
void _createTemporaryFile(char *file_path);
void _generateTemporaryPath(char *path);
void _createDirectory(char *directory_path);
void _deleteDirectory(char *directory_path);
void _createFile(char *file_path);
void _deleteFile(char *file_path);

void setUp(void)
{
	_saveCWD();
}

void tearDown(void)
{
	_restoreCWD();
}

#ifndef _WIN32 /* TODO: make windows compatible */
void testGetCurrentDir(void)
{
	char current_working_directory[PATH_LEN];

	_createTemporaryDirectory(current_working_directory);
	chdir(current_working_directory);
	char *expected = current_working_directory;

	char *result = getCurrentDir();

	TEST_ASSERT_EQUAL_STRING(expected, result);

	free(result);
	_deleteDirectory(current_working_directory);
}
#endif

#ifndef _WIN32 /* TODO: make windows compatible */
void testFileExistsTrue(void)
{
	char temporary_file[PATH_LEN];

	_createTemporaryFile(temporary_file);

	bool result = file_exists(temporary_file);

	TEST_ASSERT_TRUE(result);

	_deleteFile(temporary_file);
}
#endif

#ifndef _WIN32 /* TODO: make windows compatible */
void testFileExistsFalse(void)
{
	char temporary_file[PATH_LEN];

	_generateTemporaryPath(temporary_file);

	bool result = file_exists(temporary_file);

	TEST_ASSERT_FALSE(result);
}
#endif

#ifndef _WIN32 /* TODO: make windows compatible */
void testDirectoryExistsTrue(void)
{
	char temporary_directory[PATH_LEN];

	_createTemporaryFile(temporary_directory);

	bool result = directory_exists(temporary_directory);

	TEST_ASSERT_TRUE(result);

	_deleteDirectory(temporary_directory);
}
#endif

#ifndef _WIN32 /* TODO: make windows compatible */
void testDirectoryExistsFalse(void)
{
	char temporary_directory[PATH_LEN];

	_generateTemporaryPath(temporary_directory);

	bool result = directory_exists(temporary_directory);

	TEST_ASSERT_FALSE(result);
}
Exemplo n.º 10
0
// -----------------------------------------------------------------------------
int main()
{
    try
    {
        auto reference_datum_path = get__reference_datum_path ();
        auto action_logs_path = reference_datum_path + L"test-results\\C\\";

        wprintf(L"m3_hron - running test cases\r\n");

        if (!directory_exists (reference_datum_path))
        {
            wprintf(L"Exiting due to missing reference datum directory (%s)\r\n", reference_datum_path.c_str ());
            return 999;
        }

        if (!directory_exists (action_logs_path) && !create_directory (action_logs_path))
        {
            wprintf(L"Exiting due to missing action log directory couldn't be created (%s)\r\n", action_logs_path.c_str ());
            return 999;
        }

        unit_test           (reference_datum_path, action_logs_path);
        correctness_test    (reference_datum_path, action_logs_path);
        performance_test    (reference_datum_path, action_logs_path);

        return 0;
    }
    catch (exitcode_exception const & e)
    {
        return e.exitcode;
    }
    catch (std::exception const & e)
    {
        wprintf(L"Exiting due to error: %S\r\n", e.what ());
        return 999;
    }
    catch (...)
    {
        wprintf(L"Exiting due to unrecognized error\r\n");
        return 999;
    }
}
Exemplo n.º 11
0
std::string FileUtils::system_temporary_dir()
{
#ifdef _WIN32
    const wchar_t *value;
    std::wstring w_path;
    std::string path;

    if ((value = _wgetenv(L"TMP")) && directory_exists(value)) {
        w_path = value;
        goto done;
    }
    if ((value = _wgetenv(L"TEMP")) && directory_exists(value)) {
        w_path = value;
        goto done;
    }
    if ((value = _wgetenv(L"LOCALAPPDATA"))) {
        w_path = value;
        w_path += L"\\Temp";
        if (directory_exists(w_path.c_str())) {
            goto done;
        }
    }
    if ((value = _wgetenv(L"USERPROFILE"))) {
        w_path = value;
        w_path += L"\\Temp";
        if (directory_exists(w_path.c_str())) {
            goto done;
        }
    }

done:
    auto result = wcs_to_utf8(w_path);
    return result ? std::move(result.value()) : std::string();
#else
    const char *value;

    if ((value = getenv("TMPDIR")) && directory_exists(value)) {
        return value;
    }
    if ((value = getenv("TMP")) && directory_exists(value)) {
        return value;
    }
    if ((value = getenv("TEMP")) && directory_exists(value)) {
        return value;
    }
    if ((value = getenv("TEMPDIR")) && directory_exists(value)) {
        return value;
    }

    return "/tmp";
#endif
}
Exemplo n.º 12
0
bool install_in_shell(bool global) {
  // keep track of the number of files
  // that we've written to (should end up being 2)
  int wrote_files = 0;

  char* script = bash_script();
  if (script) {
    print_verbose("Writing \"%s\"\n", script);

    char *profile_filename = NULL;

    if (global) {
      //global mode - install in /etc/profile and /etc/bash.bashrc
      if (directory_exists("/etc/profile.d")) {
        profile_filename = "/etc/profile.d/path.sh";
      } else if (file_exists("/etc/profile")) {
        profile_filename = "/etc/profile";
      }
      if (profile_filename) {
        if (write_script(profile_filename, script)) wrote_files++;
      }
      if (file_exists("/etc/bash.bashrc")) {
        if (write_script("/etc/bash.bashrc", script)) wrote_files++;
      }
    } else {
      //user mode - install in profile, rc file
      char* home_dir = get_home_directory();
      int i;
      char* profile_search_list[] = {".bash_profile", ".bash_login", ".profile"};
      for (i = 0; i < 3; i++) {
        char* filename = file_join(home_dir, profile_search_list[i]);
        if (file_exists(filename)) {
          profile_filename = filename;
          break;
        }
        free(filename);
      }
      if (!profile_filename) {
        profile_filename = file_join(home_dir, profile_search_list[0]);
      }
      if (write_script(profile_filename, script)) wrote_files++;
      free(profile_filename);

      char* rc_filename = file_join(home_dir, ".bashrc");
      if (write_script(rc_filename, script)) wrote_files++;
      free(rc_filename);

      free(home_dir);
    }

    free(script);
  }
  return wrote_files == 2;
}
Exemplo n.º 13
0
// Given a relative or absolute filepath, create the directory hierarchy
// as needed. Returns true if the hierarchy is/was setup.
bool mkdirs(const std::string& path) {
  // TODO: all the callers do unlink && mkdirs && adb_creat ---
  // that's probably the operation we should expose.

  // Implementation Notes:
  //
  // Pros:
  // - Uses dirname, so does not need to deal with OS_PATH_SEPARATOR.
  // - On Windows, uses mingw dirname which accepts '/' and '\\', drive letters
  //   (C:\foo), UNC paths (\\server\share\dir\dir\file), and Unicode (when
  //   combined with our adb_mkdir() which takes UTF-8).
  // - Is optimistic wrt thinking that a deep directory hierarchy will exist.
  //   So it does as few stat()s as possible before doing mkdir()s.
  // Cons:
  // - Recursive, so it uses stack space relative to number of directory
  //   components.

  // If path points to a symlink to a directory, that's fine.
  struct stat sb;
  if (stat(path.c_str(), &sb) != -1 && S_ISDIR(sb.st_mode)) {
    return true;
  }

  const std::string parent(adb_dirname(path));

  // If dirname returned the same path as what we passed in, don't go recursive.
  // This can happen on Windows when walking up the directory hierarchy and not
  // finding anything that already exists (unlike POSIX that will eventually
  // find . or /).
  if (parent == path) {
    errno = ENOENT;
    return false;
  }

  // Recursively make parent directories of 'path'.
  if (!mkdirs(parent)) {
    return false;
  }

  // Now that the parent directory hierarchy of 'path' has been ensured,
  // create path itself.
  if (adb_mkdir(path, 0775) == -1) {
    const int saved_errno = errno;
    // If someone else created the directory, that is ok.
    if (directory_exists(path)) {
      return true;
    }
    // There might be a pre-existing file at 'path', or there might have been some other error.
    errno = saved_errno;
    return false;
  }

  return true;
}
Exemplo n.º 14
0
/* =============== GPL HEADER =====================
 * TuxStrings.c is part of TuxDroidServer
 * Copyleft (C) 2012 - Joel Matteotti <joel _DOT_ matteotti _AT_ free _DOT_ fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 * ====================================================
*/

#include <stdlib.h>
#include <unistd.h>

#include <unity.h>
#include "TuxUtils.h"

#define SHELL_COMMAND_LEN 256
#define PATH_LEN 256
char old_cwd[PATH_LEN];

void _saveCWD();
void _restoreCWD();
void _createTemporaryDirectory(char *directory_path);
void _createTemporaryFile(char *file_path);
void _generateTemporaryPath(char *path);
void _createDirectory(char *directory_path);
void _deleteDirectory(char *directory_path);
void _createFile(char *file_path);
void _deleteFile(char *file_path);

void setUp(void)
{
	_saveCWD();
}

void tearDown(void)
{
	_restoreCWD();
}

#ifndef _WIN32 /* TODO: make windows compatible */
void testGetCurrentDir(void)
{
	char current_working_directory[PATH_LEN];

	_createTemporaryDirectory(current_working_directory);
	chdir(current_working_directory);
	char *expected = current_working_directory;

	char *result = getCurrentDir();

	TEST_ASSERT_EQUAL_STRING(expected, result);

	free(result);
	_deleteDirectory(current_working_directory);
}
#endif

#ifndef _WIN32 /* TODO: make windows compatible */
void testFileExistsTrue(void)
{
	char temporary_file[PATH_LEN];

	_createTemporaryFile(temporary_file);

	bool result = file_exists(temporary_file);

	TEST_ASSERT_TRUE(result);

	_deleteFile(temporary_file);
}
#endif

#ifndef _WIN32 /* TODO: make windows compatible */
void testFileExistsFalse(void)
{
	char temporary_file[PATH_LEN];

	_generateTemporaryPath(temporary_file);

	bool result = file_exists(temporary_file);

	TEST_ASSERT_FALSE(result);
}
#endif

#ifndef _WIN32 /* TODO: make windows compatible */
void testDirectoryExistsTrue(void)
{
	char temporary_directory[PATH_LEN];

	_createTemporaryFile(temporary_directory);

	bool result = directory_exists(temporary_directory);

	TEST_ASSERT_TRUE(result);

	_deleteDirectory(temporary_directory);
}
Exemplo n.º 15
0
TempDir::TempDir(const string& appName)
{
  for (int i=(std::rand()%0xffff); ; ++i) {
    m_path = join_path(get_temp_path(),
                       appName + convert_to<string>(i));

    if (!directory_exists(m_path)) {
      make_directory(m_path);
      break;
    }
  }
}
Exemplo n.º 16
0
void test_create_xdg_dirs_when_xdg_directories_are_arbitrary_and_missing(void **param)
{
	//create temporary base directory
	char temp_base[] = "/tmp/flybyXXXXXXXX";
	mkdtemp(temp_base);
	assert_true(directory_exists(temp_base));

	//specify XDG directories to something arbitrary in the base directory
	char *expected_data_home = add_to_path(temp_base, "arbitrarydata/data/directory");
	char *expected_config_home = add_to_path(temp_base, "arbitraryconf/config/directory");
	setenv("XDG_DATA_HOME", expected_data_home, 1);
	setenv("XDG_CONFIG_HOME", expected_config_home, 1);
	assert_false(directory_exists(expected_data_home));
	assert_false(directory_exists(expected_config_home));

	//test directory creation
	test_create_xdg_dirs();
	
	assert_true(directory_exists(expected_data_home));
	assert_true(directory_exists(expected_config_home));
	free(expected_data_home);
	free(expected_config_home);

	//cleanup
	char *dir;
	dir = add_to_path(temp_base, "arbitrarydata/data/directory"); rmdir(dir); free(dir);
	dir = add_to_path(temp_base, "arbitrarydata/data"); rmdir(dir); free(dir);
	dir = add_to_path(temp_base, "arbitrarydata"); rmdir(dir); free(dir);
	dir = add_to_path(temp_base, "arbitraryconf/config/directory"); rmdir(dir); free(dir);
	dir = add_to_path(temp_base, "arbitraryconf/config"); rmdir(dir); free(dir);
	dir = add_to_path(temp_base, "arbitraryconf"); rmdir(dir); free(dir);
	rmdir(temp_base);
	assert_false(directory_exists(temp_base));
}
Exemplo n.º 17
0
bool check_regression(
    std::string const& prefix, Mesh* mesh, Real tol, Real floor) {
  auto comm = mesh->comm();
  auto goldpath = prefix + ".osh";
  if (!directory_exists(goldpath.c_str())) {
    if (comm->size() == 1) {
      binary::write(goldpath, mesh);
      std::cout << "gold path \"" << goldpath << "\" did not exist yet,\n";
      std::cout << "created it from this run.\n";
      return true;
    } else {
      auto tmppath = prefix + "_tmp.osh";
      binary::write(tmppath, mesh);
      if (comm->rank() == 0) {
        std::cout << "gold path \"" << goldpath;
        std::cout << "\" does not exist and this run is parallel.\n";
        std::cout << "If you really want to use this run as the gold, do:\n";
        std::cout << "  mv \"" << tmppath << "\" \"" << goldpath << "\"\n";
      }
      return false;
    }
  }
  Mesh gold_mesh(mesh->library());
  binary::read(goldpath, comm, &gold_mesh);
  auto res = compare_meshes(&gold_mesh, mesh, tol, floor, true);
  if (res == OMEGA_H_SAME) {
    if (comm->rank() == 0) {
      std::cout << "This run matches gold \"" << goldpath << "\"\n";
    }
    return true;
  }
  if (res == OMEGA_H_MORE) {
    auto newpath = prefix + "_new.osh";
    binary::write(newpath, mesh);
    if (comm->rank() == 0) {
      std::cout << "This run, stored at \"" << newpath << "\",\n";
      std::cout << "has more tags than \"" << goldpath << "\"\n";
      std::cout << "It should probably be made the new gold, like this:\n";
      std::cout << "  rm -rf \"" << goldpath << "\"\n";
      std::cout << "  mv \"" << newpath << "\" \"" << goldpath << "\"\n";
    }
    return false;
  }
  auto badpath = prefix + "_bad.osh";
  binary::write(badpath, mesh);
  if (comm->rank() == 0) {
    std::cout << "This run, stored at \"" << badpath << "\",\n";
    std::cout << "does not match the gold at \"" << goldpath << "\"\n";
  }
  return false;
}
Exemplo n.º 18
0
/* initialise the settings */
int init_settings()
{
	char directory[BLOCK_SIZE];
	char command[BLOCK_SIZE];
	char subdir[BLOCK_SIZE];
	int retval;

	settings_directory_name(directory);
	if (directory_exists(directory) != 0) return 0;

	/* create a .config directory */
	sprintf(subdir,"%s%c.config",
			getenv("HOME"), DIRECTORY_SEPARATOR);
	if (directory_exists(subdir) == 0) {
		sprintf(command,"%s %s", COMMAND_MKDIR, subdir);
		retval = system(command);
	}

	sprintf(command,"%s %s", COMMAND_MKDIR, directory);
	retval = system(command);
	
	return retval;
}
Exemplo n.º 19
0
Arquivo: ln.c Projeto: abzde/dock9
int main(string args)
{
     string file, refrence;
     
     if(!args) return(notify_fail("Syntax: ln <original file> <new refrence>\n"));
     
     if(sscanf(args, "%s %s", file, refrence) != 2) 
          return(notify_fail("Syntax: ln <original file> <new refrence>\n"));
     
     file = resolve_path(this_player()->query("cwd"), file);
     refrence = resolve_path(this_player()->query("cwd"), refrence);           
     
     if(!file_exists(file)) return(notify_fail("Error [ln]: File '" + file + "' does not exist.\n"));
     if(file_exists(refrence)) return(notify_fail("Error [ln]: File '" + refrence + "' already exists.\n"));
     if(directory_exists(file)) return(notify_fail("Error [ln]: '" + file + "' is a directory.\n"));
     if(directory_exists(refrence)) return(notify_fail("Error [ln]: '" + refrence + "' is a directory.\n"));
     if(!master()->valid_link(file, refrence)) return(notify_fail("Error [ln]: Permission denied.\n"));
     
     write((link(file, refrence) ? "Error [ln]: Linking of file '" + refrence + "' to '" + file + "' was unsuccesful.\n"
          : "Success [ln]: File '" + refrence + "' now linked to '" + file + "'.\n" ));
     
     return 1;
}
Exemplo n.º 20
0
void test_create_xdg_dirs_when_xdg_directories_are_welldefined(void **param)
{
	//create temporary directory for XDG_DATA_HOME and XDG_CONFIG_HOME
	char temp_xdg_data_home[] = "/tmp/flybyXXXXXXXX";
	mkdtemp(temp_xdg_data_home);
	setenv("XDG_DATA_HOME", temp_xdg_data_home, 1);
	assert_true(directory_exists(temp_xdg_data_home));

	char temp_xdg_config_home[] = "/tmp/flybyXXXXXXXX";
	mkdtemp(temp_xdg_config_home);
	setenv("XDG_CONFIG_HOME", temp_xdg_config_home, 1);
	assert_true(directory_exists(temp_xdg_config_home));

	//check that directories can be created correctly
	test_create_xdg_dirs();

	//cleanup
	rmdir(temp_xdg_data_home);
	rmdir(temp_xdg_config_home);

	assert_false(directory_exists(temp_xdg_data_home));
	assert_false(directory_exists(temp_xdg_config_home));
}
Exemplo n.º 21
0
static void
removeDeletedFromDirectory(struct directory *directory)
{
	int i;
	struct dirvec *dv = &directory->children;

	for (i = dv->nr; --i >= 0; ) {
		if (directory_exists(dv->base[i]))
			continue;

		g_debug("removing directory: %s", dv->base[i]->path);
		delete_directory(dv->base[i]);
		modified = true;
	}

	songvec_for_each(&directory->songs, delete_song_if_removed, directory);
}
Exemplo n.º 22
0
void sysfs_export(struct sysfs_def *def, int gpio)
{
	static char path[PATH_MAX];

	// ensure not already opened (soft_pwm crashes if reopen ??)
	snprintf(path, PATH_MAX, "/sys/class/%s/%d", def->class, gpio);
	path[PATH_MAX-1] = '\0';
	log_assert(!directory_exists(path));

	snprintf(path, PATH_MAX, "/sys/class/%s/export", def->class);
	path[PATH_MAX-1] = '\0';

	static char buffer[15];
	sprintf(buffer, "%d", gpio);

	write_value(path, buffer);
}
Exemplo n.º 23
0
/**
 * Check that full flyby config/data directories (XDG_DATA_HOME/flyby/tles,
 * XDG_CONFIG_HOME/flyby) can be created given the current definitions of
 * XDG_DATA_HOME and XDG_CONFIG_HOME and remove the directories again. Called
 * from the test_create_xdg_dirs_when_*-functions.
 **/
void test_create_xdg_dirs()
{
	//construct expected paths
	char *xdg_data_home_basepath = xdg_data_home();
	char *xdg_config_home_basepath = xdg_config_home();
	char *flyby_config_dir = add_to_path(xdg_config_home_basepath, FLYBY_RELATIVE_ROOT_PATH);
	char *flyby_data_dir = add_to_path(xdg_data_home_basepath, FLYBY_RELATIVE_ROOT_PATH);
	char *flyby_tle_dir = add_to_path(xdg_data_home_basepath, TLE_RELATIVE_DIR_PATH);

	//check that paths do not exist yet
	assert_false(directory_exists(flyby_config_dir));
	assert_false(directory_exists(flyby_data_dir));
	assert_false(directory_exists(flyby_tle_dir));

	create_xdg_dirs();

	//check that paths have been created
	assert_true(directory_exists(flyby_config_dir));
	assert_true(directory_exists(flyby_data_dir));
	assert_true(directory_exists(flyby_tle_dir));

	//cleanup
	rmdir(flyby_tle_dir);
	rmdir(flyby_data_dir);
	rmdir(flyby_config_dir);
	
	assert_false(directory_exists(flyby_config_dir));
	assert_false(directory_exists(flyby_data_dir));
	assert_false(directory_exists(flyby_tle_dir));

	free(flyby_config_dir);
	free(flyby_data_dir);
	free(flyby_tle_dir);

	free(xdg_data_home_basepath);
	free(xdg_config_home_basepath);
}
Exemplo n.º 24
0
/* Expand a file into a convenient location, nuking it each time */
static char *
expand(char *fname)
{
    char *gunzip = "/usr/bin/gunzip";

    if (!directory_exists(DOC_TMP_DIR)) {
	Mkdir(DOC_TMP_DIR);
	if (chown(DOC_TMP_DIR, 0, 0) < 0)
	    return NULL;
	if (chmod(DOC_TMP_DIR, S_IRWXU) < 0)
	    return NULL;
    }
    else
	unlink(DOC_TMP_FILE);
    if (!file_readable(fname) || vsystem("%s < %s > %s", gunzip, fname, DOC_TMP_FILE))
	return NULL;
    return DOC_TMP_FILE;
}
Exemplo n.º 25
0
std::string clean_path( const std::string &path, bool add_trailing_slash )
{
	std::string retval = path;

	if ( retval.empty() )
		return retval;

#ifdef SFML_SYSTEM_WINDOWS
	// substitute systemroot leading %SYSTEMROOT%
	if (( retval.size() >= 12 )
		&& ( retval.compare( 0, 12, "%SYSTEMROOT%" ) == 0 ))
	{
		std::string sysroot;
		str_from_c( sysroot, getenv( "SystemRoot" ) );
		retval.replace( 0, 12, sysroot );
	}
	else if (( retval.size() >= 14 )
		&& ( retval.compare( 0, 14, "%PROGRAMFILES%" ) == 0 ))
	{
		std::string pf;
		str_from_c( pf, getenv( "ProgramFiles" ) );
		retval.replace( 0, 14, pf );
	}

#endif

	// substitute home dir for leading ~
	if (( retval.size() >= 1 ) && ( retval.compare( 0, 1, "~" ) == 0 ))
		retval.replace( 0, 1, get_home_dir() );

	// substitute home dir for leading $HOME
	if (( retval.size() >= 5 ) && ( retval.compare( 0, 5, "$HOME" ) == 0 ))
		retval.replace( 0, 5, get_home_dir() );

	if (( add_trailing_slash )
#ifdef SFML_SYSTEM_WINDOWS
			&& (retval[retval.size()-1] != '\\')
#endif
			&& (retval[retval.size()-1] != '/')
			&& (directory_exists(retval)) )
		retval += '/';

	return retval;
}
Exemplo n.º 26
0
Arquivo: home.c Projeto: Elohim/FGmud
mixed GoHome(string str) {
    object ob, prev;
    string who, room;

    prev = environment(this_player());
    if( !str || str == "" || !creatorp(this_player())){
        who = this_player()->GetKeyName();
    }
    else who = lower_case(str);
    if(!user_exists(who)) return "There's no such user.";
    room = PLAYERS_D->GetHomeRoom(who);
    if(!room || !strsrch(room, "/tmp/")){
        str = user_path(who, 1);
        if(!directory_exists(str)) return "That person has no home dir.";
        str = user_path(who, 1)+"workroom.c";
        arg = str;
        if(!unguarded((: file_exists(arg) :)))
            return capitalize(who)+" has no active workroom.";
    }
static bool remount_partition(int fd, const char* dir) {
    if (!directory_exists(dir)) {
        return true;
    }
    std::string dev = find_mount(dir);
    if (dev.empty()) {
        return true;
    }
    if (!make_block_device_writable(dev)) {
        WriteFdFmt(fd, "remount of %s failed; couldn't make block device %s writable: %s\n",
                   dir, dev.c_str(), strerror(errno));
        return false;
    }
    if (mount(dev.c_str(), dir, "none", MS_REMOUNT, nullptr) == -1) {
        WriteFdFmt(fd, "remount of %s failed: %s\n", dir, strerror(errno));
        return false;
    }
    return true;
}
Exemplo n.º 28
0
static LPWSTR make_unpack_dir() {
    WCHAR buf[4*MAX_PATH] = {0};
    LPWSTR ans = NULL;

    if (directory_exists(L"_unpack_calibre_portable"))
        rmtree(L"_unpack_calibre_portable");

    if (!CreateDirectory(L"_unpack_calibre_portable", NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
        show_last_error(L"Failed to create temporary folder to unpack into");
        return ans;
    }

    if (!GetFullPathName(L"_unpack_calibre_portable", 4*MAX_PATH, buf, NULL)) {
        show_last_error(L"Failed to resolve path");
        return NULL;
    }

    ans = _wcsdup(buf);
    if (ans == NULL) show_error(L"Out of memory");
    return ans;

}
Exemplo n.º 29
0
static int sweep_dir(string dir, int when, int verbose, int flag, int test) {
   string *contents;
   int loop, dinged;
 
   if(!directory_exists(dir))  return 0;
 
   if(verbose)  write(bold("Sweeping: " + dir) + "\n");
 
   dinged = 0 ;
   contents = get_dir(dir);

   if(!contents || !sizeof(contents))  return 0;

   //	Loop through contents of the subdirectory check for compliance.
 
    for(loop=0; loop<sizeof(contents); loop++) {
	if(fail_test(dir, contents[loop], when, flag)) {
	    dinged ++ ;
        call_out( "remove_user", dinged * USER_CALL_TIME, contents[loop],
					verbose, flag, test );
	   }
	}
return 1; }
Exemplo n.º 30
0
int save_arch()
{
	char directory[BLOCK_SIZE];
	char arch_directory[BLOCK_SIZE];
	char commandstr[BLOCK_SIZE];
	int retval=0;

	get_setting("directory",directory);
	sprintf(arch_directory,"%s%c%s",
			directory, DIRECTORY_SEPARATOR,
			ARCH_SUBDIR);

	/* create a directory for building arch packages */
	if (directory_exists(arch_directory)==0) {
		sprintf(commandstr,"%s %s",
				COMMAND_MKDIR, arch_directory);
		retval = system(commandstr);
	}

	save_PKGBUILD(arch_directory);
	save_script(directory);

	return retval;
}