Exemple #1
0
int Dir::remove(const var::ConstString & path, bool recursive){
#else
int Dir::remove(const var::ConstString & path, bool recursive, link_transport_mdriver_t * driver){
#endif
	int ret = 0;
	if( recursive ){
#if defined __link
		Dir d(driver);
#else
		Dir d;
#endif
		if( d.open(path) == 0 ){
			var::String entry;
			while( (entry = d.read()).is_empty() == false ){
#if defined __link
				FileInfo info(driver);
#else
				FileInfo info;
#endif
				var::String entry_path;
				entry_path << path << "/" << entry;
				if( info.get_info(entry_path) < 0 ){

				}
				if( info.is_directory() ){
					if( entry != "." && entry != ".."){
#if defined __link
						ret = Dir::remove(entry_path, true, driver);
#else
						ret = Dir::remove(entry_path, true);
#endif
					}
				} else {
#if defined __link
					ret = File::remove(entry_path, driver);
#else
					ret = File::remove(entry_path);
#endif
				}
			}
		}
		d.close();
	}

	if( ret >= 0 ){
		//this will remove an empty directory or a file
#if defined __link
		if( driver ){
			ret = File::remove(path, driver);
		} else {
			ret = ::rmdir(path.cstring());
		}
#else
		ret = File::remove(path);
#endif
	}

	return ret;
}
Exemple #2
0
var::Vector<var::String> Dir::read_list(const var::ConstString & path, link_transport_mdriver_t * driver){
	Dir directory(driver);
#else
var::Vector<var::String> Dir::read_list(const var::ConstString & path){
	Dir directory;
#endif
	var::Vector<var::String> result;
	if( directory.open(path) < 0 ){ return result; }
	result = directory.read_list();
	directory.close();
	return result;
}
Exemple #3
0
int Dir::create(const var::ConstString & path, int mode, bool is_recursive, link_transport_mdriver_t * driver){
	if( is_recursive == false ){
		return create(path, mode, driver);
	}
#else
int Dir::create(const var::ConstString & path, int mode, bool is_recursive){
	if( is_recursive == false ){
		return create(path, mode);
	}
#endif
	var::Tokenizer path_tokens(path, "/");
	var::String base_path;

	if( path.find("/") == 0 ){
		base_path << "/";
	}

	for(u32 i=0; i < path_tokens.count(); i++){
		base_path << path_tokens.at(i);
#if defined __link
		create(base_path, mode, driver);
#else
		create(base_path, mode);
#endif
		base_path << "/";
	}


	return 0;
}



#if defined __link
bool Dir::exists(const var::ConstString & path, link_transport_mdriver_t * driver){
	Dir d(driver);
#else
bool Dir::exists(const var::ConstString & path){
	Dir d;
#endif
	if( d.open(path) < 0 ){ return false; }
	d.close();
	return true;
}
Exemple #4
0
 void test_close() {
   String* path = String::create(state, ".");
   d->open(state, path);
   TS_ASSERT_EQUALS(d->close(state), Qnil);
 }
Exemple #5
0
 void tearDown() {
   if(!d->closed_p(state)->true_p()) d->close(state);
   destroy();
 }
Exemple #6
0
 void test_close() {
   String* path = String::create(state, ".");
   d->open(state, path);
   TS_ASSERT_EQUALS(d->close(state), Qtrue);
   TS_ASSERT(d->data()->nil_p());
 }
Exemple #7
0
 void tearDown() {
   if(!d->closed_p(state)->true_p()) d->close(state);
   delete state;
 }