예제 #1
0
	void TarUtils::read( const ibrcommon::File &extract_folder, std::istream &input )
	{
		struct archive *a;
		struct archive_entry *entry;
		int ret,fd;

		a = archive_read_new();
		archive_read_support_filter_all(a);
		archive_read_support_compression_all(a);
		archive_read_support_format_tar(a);

		archive_read_open(a, (void*) &input, &__tar_utils_open_callback, &__tar_utils_read_callback, &__tar_utils_close_callback);

		while ((ret = archive_read_next_header(a, &entry)) == ARCHIVE_OK )
		{
			ibrcommon::File filename = extract_folder.get(archive_entry_pathname(entry));
			ibrcommon::File path = filename.getParent();
			ibrcommon::File::createDirectory(path);
			fd = open(filename.getPath().c_str(),O_CREAT|O_WRONLY,0600);
			if(fd < 0) throw ibrcommon::IOException("cannot open file " + path.getPath());
			archive_read_data_into_fd(a,fd);
			close(fd);
		}

		archive_read_free(a);
	}
		void FileMonitor::adopt(const ibrcommon::File &path)
		{
			// look for ".dtndrive" file
			const ibrcommon::File drivefile = path.get(".dtndrive");
			if (drivefile.exists())
			{
				ibrcommon::ConfigFile cf(drivefile.getPath());

				try {
					const dtn::data::EID eid( cf.read<std::string>("EID") );

					dtn::core::Node n(eid);
					const std::string uri = "file://" + path.getPath() + "/" + cf.read<std::string>("PATH");

					n.add(dtn::core::Node::URI(dtn::core::Node::NODE_DISCOVERED, dtn::core::Node::CONN_FILE, uri, 0, 10));
					dtn::core::BundleCore::getInstance().getConnectionManager().add(n);

					_active_paths[path] = n;

					IBRCOMMON_LOGGER_DEBUG_TAG("FileMonitor", 5) << "Node on drive found: " << n.getEID().getString() << IBRCOMMON_LOGGER_ENDL;

				} catch (const ibrcommon::ConfigFile::key_not_found&) {};
			}
		}