From d61ed49c0b13656b4d3c7d1826f633db643da246 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 9 Sep 2020 10:31:24 +0200 Subject: GUI: Do "Index this frame" in a temporary folder --- src/gui_index.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/src/gui_index.c b/src/gui_index.c index 4395a90e..f88cfa35 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -38,6 +38,9 @@ #include #include #include +#include +#include +#include #include #include @@ -408,6 +411,73 @@ static IndexingFlags indexing_flags(struct index_params *params) } +static char *enter_gui_tempdir() +{ + char *tmpdir; + struct stat s; + + tmpdir = malloc(64); + if ( tmpdir == NULL ) { + ERROR("Failed to allocate temporary directory name\n"); + return NULL; + } + snprintf(tmpdir, 63, "crystfel-gui.%i", getpid()); + + if ( stat(tmpdir, &s) == -1 ) { + + int r; + + if ( errno != ENOENT ) { + ERROR("Failed to stat temporary folder.\n"); + return NULL; + } + + r = mkdir(tmpdir, S_IRWXU); + if ( r ) { + ERROR("Failed to create temporary folder: %s\n", + strerror(errno)); + return NULL; + } + + } + + return tmpdir; +} + + +static void delete_gui_tempdir(char *tmpdir) +{ + char *path; + int i; + + /* List of files which it's safe to delete */ + char *files[] = {"gmon.out", "mosflm.lp", "SUMMARY", "XDS.INP", + "xfel_001.img", "xfel_001.spt", "xfel.drx", + "xfel.felix", "xfel.gve", "xfel.ini", "xfel.log", + "IDXREF.LP", "SPOT.XDS", "xfel.newmat", "XPARM.XDS"}; + + /* Number of items in the above list */ + int n_files = 15; + + if ( tmpdir == NULL ) return; + + path = calloc(strlen(tmpdir)+64, 1); + if ( path == NULL ) return; + + for ( i=0; iindexing_params.cell_file != NULL ) { cell = load_cell_from_file(proj->indexing_params.cell_file); @@ -429,6 +502,9 @@ static void run_indexing_once(struct crystfelproject *proj) update_peaks(proj); + old_cwd = getcwd(NULL, 0); + tmpdir = enter_gui_tempdir(); + if ( proj->indexing_params.indexing_methods == NULL ) { methods = detect_indexing_methods(cell); STATUS("Auto-detected indexng methods: %s\n", @@ -463,6 +539,14 @@ static void run_indexing_once(struct crystfelproject *proj) } } + r = chdir(old_cwd); + if ( r ) { + ERROR("Failed to chdir: %s\n", strerror(errno)); + return; + } + free(old_cwd); + delete_gui_tempdir(tmpdir); + err = 0; int_method = integration_method(proj->indexing_params.integration_method, &err); -- cgit v1.2.3