futility/updater_archive.c
/* Callback for archive_write_file on a general file system. */
Callback for archive_write_file on a general file system.
Callback for archive_write_file on a general file system .
static int archive_fallback_write_file(void *handle, const char *fname,
				       uint8_t *data, uint32_t size, int64_t mtime)
{
	int r;
	char *temp_path = NULL;
	const char *path = archive_fallback_get_path(handle, fname, &temp_path);
	VB2_DEBUG("Writing %s\n", path);
	if (strchr(path, '/')) {
		char *dirname = strdup(path);
		*strrchr(dirname, '/') = '\0';
		if (access(dirname, W_OK) != 0) {
			char *command;
			ASPRINTF(&command, "mkdir -p %s", dirname);
			free(host_shell(command));
			free(command);
		}
		free(dirname);
	}
	r = vb2_write_file(path, data, size) != VB2_SUCCESS;
	if (mtime) {
		struct timeval times[2] = {
			{.tv_sec = mtime, .tv_usec = 0},
			{.tv_sec = mtime, .tv_usec = 0},
		};
		if (utimes(path, times) != 0)
			WARN("Unable to set times on %s: %s\n", path, strerror(errno));
	}
	free(temp_path);
	return r;
}
static int archive_fallback_write_file ( void * handle , const char * fname , uint8_t * data , uint32_t size , int64_t mtime ) { int r ; char * temp_path = NULL ; const char * path = archive_fallback_get_path ( handle , fname , & temp_path ) ; VB2_DEBUG ( " \n " , path ) ; if ( strchr ( path , ' ' ) ) { char * dirname = strdup ( path ) ; * strrchr ( dirname , ' ' ) = ' \0 ' ; if ( access ( dirname , W_OK ) != 0 ) { char * command ; ASPRINTF ( & command , " " , dirname ) ; free ( host_shell ( command ) ) ; free ( command ) ; } free ( dirname ) ; } r = vb2_write_file ( path , data , size ) != VB2_SUCCESS ; if ( mtime ) { struct timeval times [ 2 ] = { { . tv_sec = mtime , . tv_usec = 0 } , { . tv_sec = mtime , . tv_usec = 0 } , } ; if ( utimes ( path , times ) != 0 ) WARN ( " \n " , path , strerror ( errno ) ) ; } free ( temp_path ) ; return r ; }
Callback for archive_write_file on a general file system.
Callback for archive_write_file on a general file system .
/* TODO(hungte): call mkdir(2) instead of shell invocation. */