示例#1
0
static void swupdate_cleanup(void)
{
#ifndef CONFIG_NOCLEANUP
	remove_directory(SCRIPTS_DIR_SUFFIX);
	remove_directory(DATADST_DIR_SUFFIX);
#endif
}
示例#2
0
//* 
//* AROMA Installer Main Executable
//* 
int main(int argc, char **argv) {
  int retval = 1;
  parent_pid = getppid();
  
  //-- Normal Updater Sequences
  setbuf(stdout, NULL);
  setbuf(stderr, NULL);
  
  remove_directory(AROMA_TMP);
  create_directory(AROMA_TMP);

  //-- Initializing Header
  printf("Starting " AROMA_NAME " version " AROMA_VERSION "\n"
         "     " AROMA_COPY "\n");

  //-- Check Arguments
  if (argc != 4) {
      LOGE("Unexpected Number of Arguments (%d)\n", argc);
      return 1;
  }
  
  //-- Check CWM Version
  if ((argv[1][0] != '1' && argv[1][0] != '2' && argv[1][0] != '3') || argv[1][1] != '\0') {
      LOGE("Wrong Updater Binary API!!! Expected 1, 2, or 3, But got %s\n", argv[1]);
      return 2;
  }
  
  //-- Save to Argument
  snprintf(currArgv[0],255,"%s",argv[1]);
  snprintf(currArgv[1],255,"%s",argv[3]);
  
  //-- Init Pipe & Show Splash Info
  a_splash(argv[2]);
  if (az_init(argv[3])){
    a_init_all();
    if (parent_pid) kill(parent_pid,19);
    if (aui_start()){
      fprintf(apipe(),"ui_print\n");
      fprintf(apipe(),"ui_print " AROMA_NAME " Finished...\n");
      fprintf(apipe(),"ui_print\n");
      retval = 0;
    }
    if (parent_pid) kill(parent_pid,18);
    a_release_all();
  }
  
  //-- REMOVE AROMA TEMPORARY
  remove_directory(AROMA_TMP);
  
  //-- Check Reboot
  a_check_reboot();
  
  //-- Cleanup PIPE
  fclose(acmd_pipe);
  
  return retval;
}
示例#3
0
int main(int argc, char **argv)
{
	int i;
	char *p, ident[256];

	// print usage if required
	if (argc < 3) {
		printf("Syntax: %s <input.bin> <output.c> [<identifier>]\n", remove_directory(argv[0]));
		return -1;
	}

	// open source bin file
	FILE *fi = fopen(argv[1], "rb");
	if (!fi) {
		printf("Error opening input file!\n");
		return -1;
	}

	// open destination C file
	FILE *fo = fopen(argv[2], "w");
	if (!fo) {
		printf("Error opening output file!\n");
		return -1;
	}

	// copy/generate identifier
	if (argc >= 4) {
		strcpy(ident, argv[3]);
	} else {
		strcpy(ident, remove_directory(argv[1]));
		p = strrchr(ident, '.');	// remove extension too
		if (p) *p = 0;
	}

	// convert data
	fprintf(fo, "const unsigned char %s[] =\n{\n", ident);
	while (!feof(fi)) {
		for (i=0; i<ENTRIES_PER_LINE; i++) {
			int c = fgetc(fi);
			if (c < 0) break;
			if (i == 0) fprintf(fo, "\t");
			fprintf(fo, "0x%02X,", c);
		}
		if (i) fprintf(fo, "\n");
	}
	fprintf(fo, "};\n");

	// close files and exit
	fclose(fi);
	fclose(fo);
	return 0;
}
示例#4
0
void remove_directory(const char* path)
{
	DIR* dir;
	dirent* pdir;

	dir = opendir(path);

	while ((pdir = readdir(dir)))
	{
		if (strcmp(pdir->d_name, ".") == 0 || strcmp(pdir->d_name, "..") == 0)
			continue;

		if (pdir->d_type == DT_DIR)
		{
			pstring _dir;
			_dir << path << "/" << pdir->d_name;

			remove_directory(_dir.c_str());
		}
		else if (pdir->d_type == DT_REG)
		{
			pstring file;
			file << path << "/" << pdir->d_name;

			unlink(file.c_str());
		}
	}

	rmdir(path);
}
示例#5
0
END_TEST

START_TEST(dbcheck_with_filled_cache)
{
	int forcesave = 0;

	linuxonly;

	initdb();
	defaultcfg();
	disable_logprints();
	ck_assert_int_eq(remove_directory(TESTDIR), 1);

	ck_assert_int_eq(cachecount(), 0);
	strcpy(data.interface, "ethbasic");
	ck_assert_int_eq(cacheupdate(), 1);
	strcpy(data.interface, "ethactive");
	ck_assert_int_eq(cacheupdate(), 1);
	strcpy(data.interface, "ethnotactive");
	data.active = 0;
	ck_assert_int_eq(cacheupdate(), 1);
	ck_assert_int_eq(cachecount(), 3);
	ck_assert_int_eq(cacheactivecount(), 2);

	fake_proc_net_dev("w", "ethbasic", 1, 2, 3, 4);
	fake_proc_net_dev("a", "ethnotactive", 5, 6, 7, 8);

	ck_assert_int_ne(dbcheck(0, &forcesave), 0);
	ck_assert_int_eq(forcesave, 1);
}
示例#6
0
文件: UFS.c 项目: AntoineGagne/TPOS
int bd_rmdir(const char *pFilename) {
    int iNode = find_iNode(pFilename);
    if (iNode == -1) {
        return iNode;
    }

    int isDirectory = is_directory(iNode);
    if (!isDirectory) {
        return -2;
    }

    int isDirectoryEmpty = is_directory_empty(iNode);
    if (isDirectoryEmpty == -3) {
        return isDirectoryEmpty;
    }

    char parentPath[strlen(pFilename)];
    GetDirFromPath(pFilename, parentPath);
    int parentiNode = find_iNode(parentPath);

    char filename[FILENAME_SIZE];
    GetFilenameFromPath(pFilename, filename);

    remove_directory(iNode, parentiNode, filename);

    return 0;
}
示例#7
0
 void test_read() {
   char *dir = make_directory();
   String* path = String::create(state, dir);
   d->open(state, path);
   String* name = as<String>(d->read(state));
   TS_ASSERT_EQUALS(name->c_str()[0], '.');
   remove_directory(dir);
 }
示例#8
0
void TempDir::attach(const string& path)
{
  if (!m_path.empty())
    remove_directory(m_path);

  ASSERT(directory_exists(path));
  m_path = path;
}
示例#9
0
 void test_read_returns_nil_when_no_more_entries() {
   char *dir = make_directory();
   String* path = String::create(state, dir);
   d->open(state, path);
   d->read(state);
   d->read(state);
   TS_ASSERT(d->read(state)->nil_p());
   remove_directory(dir);
 }
示例#10
0
END_TEST

START_TEST(readproc_no_file)
{
	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	ck_assert_int_eq(readproc("ethunusual"), 0);
}
示例#11
0
static int hello_rmdir(const char* path)
{

	/* check if directory is empty first */
	struct simple_directory *d = find_directory(root_directory, path);
	if (d->num_files > 0 || d->num_directories > 0)
		return -ENOTEMPTY;

	return remove_directory(root_directory, path);
}
示例#12
0
	void remove_directories(const std::string & dir)
	{
		std::stack<std::string> directories;

		directories.push(dir);

		while(!directories.empty())
		{
			std::string	current = directories.top();

			if(is_empty(current))
			{
				remove_directory(current);

				directories.pop();

				continue;
			}

			directory_iterator_t iter(current),end;

			for(;iter != end; ++ iter)
			{
				if("." == *iter) continue;

				if(".." == *iter) continue;

				std::string path = current + "/" + *iter;

				if(is_directory(path))
				{
					if(is_empty(path)) remove_directory(path);

					else directories.push(path);
				}
				else
				{
					remove_file(path);
				}
			}
		}
	}
示例#13
0
END_TEST

START_TEST(readsysclassnet_not_found)
{
	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_sys_class_net("ethwrong", 10, 20, 30, 40, 50);

	ck_assert_int_eq(readsysclassnet("ethunusual"), 0);
}
示例#14
0
END_TEST

START_TEST(readproc_not_found)
{
	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40);

	ck_assert_int_eq(readproc("ethunusual"), 0);
}
示例#15
0
 void test_control_rewinds_read_location() {
   char *dir = make_directory();
   String* path = String::create(state, dir);
   d->open(state, path);
   d->read(state);
   d->read(state);
   TS_ASSERT(d->read(state)->nil_p());
   d->control(state, Fixnum::from(1), Fixnum::from(0));
   String* name = as<String>(d->read(state));
   TS_ASSERT_EQUALS(name->c_str()[0], '.');
   remove_directory(dir);
 }
示例#16
0
END_TEST

START_TEST(dbcheck_with_no_interfaces)
{
	int forcesave = 0;

	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	ck_assert_int_eq(dbcheck(0, &forcesave), 0);
	ck_assert_int_eq(forcesave, 0);
}
示例#17
0
END_TEST

START_TEST(getifinfo_not_found)
{
	linuxonly;

	suppress_output();
	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40);

	ck_assert_int_eq(getifinfo("ethunusual"), 0);
}
示例#18
0
文件: test-setgid.c 项目: Goon83/SALB
/**
 * \retval 0 Success
 * \retval !0 Failure 
 */
int destroy_setgid(const char * directory, struct common_options* opts)
{
    int  ret = 0;
   
    ret = remove_directory(directory, opts->use_pvfs2_lib, opts->verbose);
   
    if(ret != TEST_COMMON_SUCCESS)
    {
        printf("\tUnable to remove directory [%s]\n", directory);
    }

    return ret;
}
示例#19
0
  void test_control_seeks_to_a_known_position() {
    char *dir = make_directory();
    String* path = String::create(state, dir);
    d->open(state, path);
    d->read(state);
    Fixnum* pos = (Fixnum*)d->control(state, Fixnum::from(2), Fixnum::from(0));
    String* first = as<String>(d->read(state));

    d->control(state, Fixnum::from(0), pos);
    String* second = as<String>(d->read(state));
    TS_ASSERT_EQUALS(first->size(), second->size());
    TS_ASSERT_SAME_DATA(first, second, first->size());
    remove_directory(dir);
  }
示例#20
0
END_TEST

START_TEST(getiflist_no_source)
{
	char *ifacelist;

	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	ck_assert_int_eq(getiflist(&ifacelist, 0), 0);
	ck_assert_str_eq(ifacelist, "");

	free(ifacelist);
}
示例#21
0
END_TEST

START_TEST(dbcheck_with_empty_cache)
{
	int forcesave = 0;

	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_proc_net_dev("w", "ethsomething", 1, 2, 3, 4);
	fake_proc_net_dev("a", "ethelse", 5, 6, 7, 8);

	ck_assert_int_ne(dbcheck(0, &forcesave), 0);
	ck_assert_int_eq(forcesave, 0);
}
示例#22
0
ErrnoError remove_directory(const std::string& path, bool is_recursive) {
  if (path.empty()) {
    return make_error_perror("remove_directory", EINVAL);
  }

  std::string pr_path = prepare_path(path);
  if (pr_path[pr_path.length() - 1] == get_separator<char>()) {
    pr_path[pr_path.length() - 1] = 0;
  }

  const char* pr_path_ptr = pr_path.c_str();
  if (is_recursive) {
    DIR* dirp = opendir(pr_path_ptr);
    if (!dirp) {
      return ErrnoError();
    }

    struct dirent* p;
    while ((p = readdir(dirp)) != nullptr) {
      /* Skip the names "." and ".." as we don't want to recurse on them. */
      if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) {
        continue;
      }

      char pathBuffer[PATH_MAX] = {0};
      SNPrintf(pathBuffer, sizeof(pathBuffer), "%s/%s", path, p->d_name);
      struct stat statbuf;
      if (!::stat(pathBuffer, &statbuf)) {
        if (S_ISDIR(statbuf.st_mode)) {
          ErrnoError err = remove_directory(pathBuffer, is_recursive);
          if (err) {
            closedir(dirp);
            return err;
          }
        } else {
          ErrnoError err = remove_file(pathBuffer);
          if (err) {
            closedir(dirp);
            return err;
          }
        }
      }
    }
    closedir(dirp);
  }

  return do_rmdir_directory(pr_path_ptr);
}
示例#23
0
END_TEST

START_TEST(getiflist_proc_one_interface)
{
	char *ifacelist;

	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_proc_net_dev("w", "ethunusual", 0, 0, 0, 0);

	ck_assert_int_eq(getiflist(&ifacelist, 1), 1);
	ck_assert_str_eq(ifacelist, "lo ethunusual ");

	free(ifacelist);
}
示例#24
0
END_TEST

START_TEST(getiflist_sysclassnet_one_interface_with_speed)
{
	char *ifacelist;

	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_sys_class_net("ethunusual", 0, 0, 0, 0, 10);

	ck_assert_int_eq(getiflist(&ifacelist, 1), 1);
	ck_assert_str_eq(ifacelist, "ethunusual (10 Mbit) ");

	free(ifacelist);
}
示例#25
0
int remove_directory(const char *path)
{
   DIR *d = opendir(path);
   size_t path_len = strlen(path);
   int r = -1;
   if (d)
   {
      struct dirent *p;
      r = 0;
      while (!r && (p=readdir(d)))
      {
          int r2 = -1;
          char *buf;
          size_t len;
          if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
          {
             continue;
          }
          len = path_len + strlen(p->d_name) + 2; 
          buf = malloc(len);
          if (buf)
          {
             struct stat statbuf;
             snprintf(buf, len, "%s/%s", path, p->d_name);
             if (!stat(buf, &statbuf))
             {
                if (S_ISDIR(statbuf.st_mode))
                {
                   r2 = remove_directory(buf);
                }
                else
                {
                   r2 = unlink(buf);
                }
             }
             free(buf);
          }
          r = r2;
      }
      closedir(d);
   }
   if (!r)
   {
      r = rmdir(path);
   }
   return r;
}
示例#26
0
static ExtractTest*
extract_test_new (const char *test_name)
{
  ExtractTest *extract_test;
  g_autoptr (GFile) work_directory = NULL;
  GFile *input;
  GFile *output;
  GFile *reference;

  work_directory = g_file_get_child (extract_tests_dir, test_name);
  if (g_file_query_file_type (work_directory, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) {
    g_printerr ("%s: work directory does not exist", test_name);

    return NULL;
  }

  input = g_file_get_child (work_directory, "input");
  reference = g_file_get_child (work_directory, "reference");

  if (g_file_query_file_type (input, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY ||
      g_file_query_file_type (reference, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) {
    g_printerr ("%s: input or output directory does not exist\n", test_name);

    g_object_unref (input);

    return NULL;
  }

  output = g_file_get_child (work_directory, "output");

  remove_directory (output);

  g_file_make_directory_with_parents (output, NULL, NULL);

  extract_test = g_new0 (ExtractTest, 1);

  extract_test->input = input;
  extract_test->reference = reference;
  extract_test->output = output;

  extract_test->unmatched_files = g_hash_table_new_full (g_str_hash,
                                                         g_str_equal,
                                                         g_free,
                                                         g_object_unref);

  return extract_test;
}
示例#27
0
 void check_sub_directory(const std::string &dirname, bool add_sub_directory)
 {
     boost::filesystem::directory_iterator end;
     for (boost::filesystem::directory_iterator iter(dirname); iter != end; ++iter) {
         if (boost::filesystem::is_directory(*iter)) {
             if (add_sub_directory) {
                 try {
                     add_directory((*iter).path().string());
                 } catch (const std::exception&) {
                     continue;
                 }
             } else {
                 remove_directory((*iter).path().string());
             }
         }
     }
 }
示例#28
0
END_TEST

START_TEST(readproc_success)
{
	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40);
	fake_proc_net_dev("a", "ethunusual", 1, 2, 3, 4);

	ck_assert_int_eq(readproc("ethunusual"), 1);
	ck_assert_str_eq(ifinfo.name, "ethunusual");
	ck_assert_int_eq(ifinfo.filled, 1);
	ck_assert_int_eq(ifinfo.rx, 1);
	ck_assert_int_eq(ifinfo.tx, 2);
	ck_assert_int_eq(ifinfo.rxp, 3);
	ck_assert_int_eq(ifinfo.txp, 4);
}
示例#29
0
END_TEST

START_TEST(readsysclassnet_success)
{
	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_sys_class_net("ethwrong", 10, 20, 30, 40, 50);
	fake_sys_class_net("ethunusual", 1, 2, 3, 4, 5);

	ck_assert_int_eq(readsysclassnet("ethunusual"), 1);
	ck_assert_str_eq(ifinfo.name, "ethunusual");
	ck_assert_int_eq(ifinfo.filled, 1);
	ck_assert_int_eq(ifinfo.rx, 1);
	ck_assert_int_eq(ifinfo.tx, 2);
	ck_assert_int_eq(ifinfo.rxp, 3);
	ck_assert_int_eq(ifinfo.txp, 4);
}
示例#30
0
static gboolean
remove_directory (GFile *directory)
{
  gboolean success = TRUE;
  GError *error = NULL;
  g_autoptr (GFileEnumerator) enumerator = NULL;

  enumerator = g_file_enumerate_children (directory,
                                          G_FILE_ATTRIBUTE_STANDARD_NAME,
                                          G_FILE_QUERY_INFO_NONE,
                                          NULL, NULL);

  if (enumerator) {
    GFileInfo *info;

    while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
      g_autoptr (GFile) child;

      child = g_file_get_child (directory, g_file_info_get_name (info));

      if (!g_file_delete (child, NULL, &error)) {
        if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_EMPTY)) {
          success = success && remove_directory (child);
        } else {
          success = FALSE;
        }

        g_clear_error (&error);
      }

      g_object_unref (info);
    }
  }

  g_file_delete (directory, NULL, &error);

  if (error) {
    success = FALSE;
    g_error_free (error);
  }

  return success;
}