gchar * lsq_archive_request_temp_file ( LSQArchive *archive, const gchar *sfx ) { gchar dirname[256]; gint handle; g_return_val_if_fail( LSQ_IS_ARCHIVE( archive ), NULL ); g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/", g_get_tmp_dir(), g_get_user_name() ); if ( 0 != g_mkdir_with_parents( dirname, 0700 ) ) { return NULL; } g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/file-XXXXXX%s", g_get_tmp_dir(), g_get_user_name(), ( NULL != sfx ) ? sfx : "" ); handle = g_mkstemp( dirname ); if ( -1 == handle ) { return NULL; } close( handle ); return g_strdup( dirname ); }
void lsq_tempfs_clean_root_dir ( LSQArchive *archive ) { GSList *iter; g_return_if_fail( LSQ_IS_ARCHIVE( archive ) ); if ( NULL == archive->temp_dir ) { return; } lsq_tempfs_clean_dir( archive->temp_dir ); #ifdef DEBUG g_debug( "clean %s", archive->temp_dir ); #endif iter = archive->monitor_list; while ( NULL != iter ) { /* g_free(((LSQTempFileMonitor*)iter->data)->filename); */ g_free( iter->data ); iter = g_slist_next( iter ); } g_slist_free( archive->monitor_list ); archive->monitor_list = NULL; g_free( archive->temp_dir ); archive->temp_dir = NULL; }
gboolean lsq_tempfs_make_root_dir ( LSQArchive *archive ) { gint error = 0; gchar dirname[256]; g_return_val_if_fail( LSQ_IS_ARCHIVE( archive ), FALSE ); if ( NULL != archive->temp_dir ) { return TRUE; } g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/", g_get_tmp_dir(), g_get_user_name() ); if ( 0 != g_mkdir_with_parents( dirname, 0700 ) ) { return FALSE; } do { g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/cache-%d/", g_get_tmp_dir(), g_get_user_name(), suffix++ ); error = g_mkdir( dirname, 0700 ); } while ( 0 != error && EEXIST == errno ); if ( 0 == error ) { archive->temp_dir = g_strdup( dirname ); return TRUE; } return FALSE; }
LSQArchiveCommand * lsq_archive_command_new(const gchar *comment, LSQArchive *archive, LSQCommandFunc exec_command) { LSQArchiveCommand *archive_command; #ifdef DEBUG g_return_val_if_fail ( NULL != archive, NULL ); g_return_val_if_fail ( LSQ_IS_ARCHIVE(archive), NULL ); #endif archive_command = g_object_new(LSQ_TYPE_ARCHIVE_COMMAND, NULL); g_object_ref(G_OBJECT(archive)); archive_command->archive = archive; if ( NULL != comment ) { archive_command->comment = g_strdup(comment); } archive_command->execute = exec_command; return archive_command; }
/** * lsq_archive_command_executr: * @command: the archive_command to be executed * * Returns: true on success */ gboolean lsq_archive_command_execute(LSQArchiveCommand *command) { #ifdef DEBUG g_return_val_if_fail ( NULL != command->archive, FALSE ); g_return_val_if_fail ( LSQ_IS_ARCHIVE(command->archive), FALSE ); #endif /* DEBUG */ return command->execute(command); }
const gchar * lsq_tempfs_get_root_dir ( LSQArchive *archive ) { g_return_val_if_fail( LSQ_IS_ARCHIVE( archive ), NULL ); if ( NULL != archive->temp_dir ) { if ( FALSE == lsq_tempfs_make_root_dir( archive ) ) { return NULL; } } return archive->temp_dir; }
gboolean lsq_tempfs_make_dir ( LSQArchive *archive, const gchar *path, gint mode ) { gchar *full_path; gint error; g_return_val_if_fail( LSQ_IS_ARCHIVE( archive ), FALSE ); g_return_val_if_fail( NULL == path, FALSE ); if ( NULL == archive->temp_dir ) { if ( FALSE == lsq_tempfs_make_root_dir( archive ) ) { return FALSE; } } full_path = g_build_filename( archive->temp_dir, path, NULL ); error = g_mkdir_with_parents( full_path, mode ); g_free( full_path ); if ( 0 == error ) { return TRUE; } else { return FALSE; } }