1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-08-25 06:31:43 +02:00

Fix text back end for read-only directories (make distcheck in qmckl)

This commit is contained in:
Anthony Scemama 2021-10-13 17:43:15 +02:00
parent d017306706
commit 5cf12131f1

View File

@ -172,7 +172,24 @@ trexio_text_init (trexio_t* const file)
f->lock_file = open(file_name,O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (f->lock_file <= 0) {
if (file->mode != 'r') {
return TREXIO_ERRNO;
} else {
if (errno == EACCES) {
/* The directory is read-only and the lock file can't be written.
Create a dummy temporary file for dummy locking.
*/
char dirname[TREXIO_MAX_FILENAME_LENGTH] = "/tmp/trexio.XXXXXX";
mkdtemp(dirname);
strncpy (file_name, dirname, TREXIO_MAX_FILENAME_LENGTH);
strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name));
f->lock_file = open(file_name,O_WRONLY|O_CREAT|O_TRUNC, 0644);
remove(file_name);
rmdir(dirname);
} else {
return TREXIO_ERRNO;
}
}
}
return TREXIO_SUCCESS;