futility/updater_archive.c
/*
 * Opens an archive from given path.
 * The type of archive will be determined automatically.
 * Returns a pointer to reference to archive (must be released by archive_close
 * when not used), otherwise NULL on error.
 */
Opens an archive from given path.
The type of archive will be determined automatically.
Returns a pointer to reference to archive (must be released by archive_close
when not used), otherwise NULL on error.
Opens an archive from given path . The type of archive will be determined automatically . Returns a pointer to reference to archive ( must be released by archive_close when not used ) otherwise NULL on error .
struct archive *archive_open(const char *path)
{
	struct stat path_stat;
	struct archive *ar;
	if (stat(path, &path_stat) != 0) {
		ERROR("Cannot identify type of path: %s\n", path);
		return NULL;
	}
	ar = (struct archive *)malloc(sizeof(*ar));
	if (!ar) {
		ERROR("Internal error: allocation failure.\n");
		return NULL;
	}
	if (S_ISDIR(path_stat.st_mode)) {
		VB2_DEBUG("Found directory, use fallback (fs) driver: %s\n",
			  path);
		ar->open = archive_fallback_open;
		ar->close = archive_fallback_close;
		ar->walk = archive_fallback_walk;
		ar->has_entry = archive_fallback_has_entry;
		ar->read_file = archive_fallback_read_file;
		ar->write_file = archive_fallback_write_file;
	} else {
#ifdef HAVE_LIBZIP
		VB2_DEBUG("Found file, use ZIP driver: %s\n", path);
		ar->open = archive_zip_open;
		ar->close = archive_zip_close;
		ar->walk = archive_zip_walk;
		ar->has_entry = archive_zip_has_entry;
		ar->read_file = archive_zip_read_file;
		ar->write_file = archive_zip_write_file;
#else
		ERROR("Found file, but no drivers were enabled: %s\n", path);
		free(ar);
		return NULL;
#endif
	}
	ar->handle = ar->open(path);
	if (!ar->handle) {
		ERROR("Failed to open archive: %s\n", path);
		free(ar);
		return NULL;
	}
	return ar;
}
struct archive * archive_open ( const char * path ) { struct stat path_stat ; struct archive * ar ; if ( stat ( path , & path_stat ) != 0 ) { ERROR ( " \n " , path ) ; return NULL ; } ar = ( struct archive * ) malloc ( sizeof ( * ar ) ) ; if ( ! ar ) { ERROR ( " \n " ) ; return NULL ; } if ( S_ISDIR ( path_stat . st_mode ) ) { VB2_DEBUG ( " \n " , path ) ; ar -> open = archive_fallback_open ; ar -> close = archive_fallback_close ; ar -> walk = archive_fallback_walk ; ar -> has_entry = archive_fallback_has_entry ; ar -> read_file = archive_fallback_read_file ; ar -> write_file = archive_fallback_write_file ; } else { #ifdef HAVE_LIBZIP VB2_DEBUG ( " \n " , path ) ; ar -> open = archive_zip_open ; ar -> close = archive_zip_close ; ar -> walk = archive_zip_walk ; ar -> has_entry = archive_zip_has_entry ; ar -> read_file = archive_zip_read_file ; ar -> write_file = archive_zip_write_file ; #else ERROR ( " \n " , path ) ; free ( ar ) ; return NULL ; #endif } ar -> handle = ar -> open ( path ) ; if ( ! ar -> handle ) { ERROR ( " \n " , path ) ; free ( ar ) ; return NULL ; } return ar ; }
Opens an archive from given path.
Opens an archive from given path .
/* Regular file system. */