Пример #1
0
TiObj Filesystem::error(std::string msg, std::string url){
	TiObj out;
	out.set("class", "Error");
	out.set("msg", msg);
	out.set("url", url);
	return out;
}
Пример #2
0
void Filesystem::folder_sysobj(TiObj& out, std::string url){
	out.clear();
	string descfile = path_add(url,".sysobj.ti");
	if ( this->exists(descfile) ){
		out.load(descfile);
	}
	if ( out.classe() == "" ){
		out.set("class", "Folder");
	} else if ( !out.is("Folder") ){
		out.set("class", "Folder:"+out.classe());
	}
}
Пример #3
0
	TiObj* getObject(TiVar& var){
		if ( var.isObj() )
			return &var.atObj();
		TiObj* obj = new TiObj;
		obj->set("txt", var.atStr());
		return obj;
	}
Пример #4
0
std::string path_context (std::string classe, std::string _url){
	string url;
	if ( _url == "" )
		url = path_absolute(".");
	else
		url = path_absolute(_url);

	Filesystem fs;
	TiObj aux;

	while (true){
		if ( url.size() == 0 )
			return "";
		aux.set( "class", fs.folder_type(url) );
		if ( aux.is(classe) ){
			break;
		}

		if ( url == "/" ){
			return "";
		} else {
			int i;
			for ( i=url.size()-1; i>0; i--){
				if ( url[i] == '/' ){
					break;
				}
			}
			if ( i == 0 )
				url.resize(1);
			else
				url.resize(i);
		}
	}
	return url;
}
Пример #5
0
TiObj Filesystem::ls (std::string url) {
	TiObj out;
	this->log( __FUNCTION__ );

	string real_url = this->path_set(url);
	DIR *dp;
	struct stat buf;
	struct dirent *ep;
	dp = opendir (real_url.c_str());
	if (dp != NULL){
		string item, item_url;
		while ( ep = readdir(dp) ){

			if ( strcmp(ep->d_name,".")==0 || strcmp(ep->d_name,"..")==0 )
				continue;
			item = path_add(url, ep->d_name);
			item_url = path_add(real_url, ep->d_name);
			if ( stat(item_url.c_str(), &buf) != -1 ){
				if (S_ISREG (buf.st_mode) ){
					string tmp = ep->d_name;
					TiObj novo;
					novo.set("class", this->file_type(ep->d_name) );
					novo.set("name", tmp);
					novo.set( "url", item);
					out.box() += novo;
				} else if (S_ISDIR (buf.st_mode) ){
					TiObj novo;
					this->folder_sysobj( novo, item_url );
					novo.set( "url", item);
					if ( !novo.has("name") )
						novo.set("name", ep->d_name);
					out.box() += novo;
				}
			}

		}
		closedir(dp);
	} else {
		return this->error( strerror(errno), url );
	}

	return out;
}
Пример #6
0
TiObj Filesystem::info(std::string url){
	TiObj out;
	struct stat buf;
	string file_url = this->path_set(url);
	if ( stat(file_url.c_str(), &buf) ){
		return this->error( strerror(errno), url );
	}

	// Set node variables
	struct tm* clock;
	char strbuf[1024];
	int permission = ((buf.st_mode & S_IRWXU) >> 6)*100 + ((buf.st_mode & S_IRWXG) >> 3)*10 + ((buf.st_mode & S_IRWXO));

	out.set("permission", (long int) permission );
	out.set("inode", (long int) buf.st_ino );
	out.set("name", path_last(file_url) );
	out.set("url", path_absolute(file_url) );
	out.set("uid", (long int) buf.st_uid );
	out.set("gid", (long int)buf.st_gid );
	out.set("size_bytes",  (long int)buf.st_size );
	out.set("size_blocks", (long int)buf.st_blocks );
	out.set("block_size",  (long int)buf.st_blksize );

	clock = gmtime(&(buf.st_atime));
	sprintf(strbuf,"%d/%d/%d,%d:%d:%d",clock->tm_year+1900,clock->tm_mon+1,clock->tm_mday,clock->tm_hour,clock->tm_min,clock->tm_sec);
	out.set("atime", strbuf);
	clock = gmtime(&(buf.st_mtime));
	sprintf(strbuf,"%d/%d/%d,%d:%d:%d",clock->tm_year+1900,clock->tm_mon+1,clock->tm_mday,clock->tm_hour,clock->tm_min,clock->tm_sec);
	out.set("mtime", strbuf);
	clock = gmtime(&(buf.st_ctime));
	sprintf(strbuf,"%d/%d/%d,%d:%d:%d",clock->tm_year+1900,clock->tm_mon+1,clock->tm_mday,clock->tm_hour,clock->tm_min,clock->tm_sec);
	out.set("ctime", strbuf);

	// Get node type
	if (S_ISREG (buf.st_mode)){
		out.classe() = this->file_type(file_url);
	} else if (S_ISLNK(buf.st_mode)){
		out.classe() = "Link";
	} else if (S_ISDIR (buf.st_mode)){
		out.classe() = this->folder_type(file_url);
	}
	return out;
}