GenericMappingTools / GenericMappingTools/gmt

Better cleaning of sessions sub-directories

Open
#6,120 6 comments 0 reactions 1 assignee Claimed by @PaulWessel View on GitHub
feature request
Dominant language
C
Stars
979
Forks
414
Avg merge
17h 26m
Merged PRs (30d)
54

Description

**Description of the desired feature**

Given recent anecdotal stories on the [forum](https://forum.generic-mapping-tools.org/t/question-about-gmt-session-folder/2436/12) about huge amounts of disk space taken up by long-dead GMT sessions, it seems reasonable to restate some goals and possible solutions to make things better. Some goals:

1. No `gmt_session.######` directory should remain when a session is over
2. No active `gmt_session.######` directory should be accidentally removed

We recently implemented the handling of Ctrl-C interrupts so that the session directory is removed upon exit. However, we have lots of other situations that could need handling:

1. When a GMT module returns with an error code (say, failing to parse a badly formatted **-R** or **-J**)
2. When a non-GMT tool fails in a GMT script

In either case, the GMT script will most likely fail to give a valid result or figure. I see different solutions for these cases:

1. When a GMT module returns a non-zero status we could terminate the session before returning. If the command is in a bash script then the **set -e** part will exit the script so that no other commands will be run. We do this by simply inserting another command in the bailout macros along the lines of `if (code) gmtlib_terminate_session;` Wrappers can also check the error return and take any evasive actions suitable.
2. When a non-GMT command fails we would need the bash script to have set a trap so that an error triggers a `gmt clear this` (or similar command before exiting.

A final _ad-hoc_ cleaning up scheme could be when **gmt end** is called: It could examine the contents in the sessions directory, get a list of all the PPID embedded, and then determine if these are current processes or not. If not a current process then we delete the corresponding directory.

Happy to entertain comments on these possibilities!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.