[getdata-devel] Patch for temporary file creation
Scientific Database Format
Brought to you by:
ketiltrout
|
From: <sf-...@sn...> - 2013-04-22 18:22:11
|
Hi Don-
I'd like to propose the attached patch. It moves the responsibility
for temporary file creation to the encoder, instead of passing in an
already opened file descriptor. The justification for the change is
to allow expandability for encodings to use fields that don't
correspond to a specific file in the directory (e.g. the zzip
interface).
I'd like to submit an additional patch to add HDF encoding to getdata
but the attached patch is a pre-req that touches other encodings as
well, so I'm proposing it separately. I think this will provide for
greater expandability in the future as well.
Of note: I don't change the oop writes, which also use temporary
files. I think that this could be addressed in the future by the
addition of a GD_FILE_OOP flag.
Let me know if you have any questions, concerns, suggestions, etc.
Best-
Seth
Index: src/ascii.c
===================================================================
diff --git a/trunk/getdata/src/ascii.c b/trunk/getdata/src/ascii.c
--- a/trunk/getdata/src/ascii.c (revision 830)
+++ b/trunk/getdata/src/ascii.c (working copy)
@@ -37,13 +37,14 @@
file->idata = gd_OpenAt(file->D, fd, file->name, ((mode & GD_FILE_WRITE)
? (O_RDWR | O_CREAT) : O_RDONLY) | O_BINARY, 0666);
- if (file->idata < 0) {
- dreturn("%i", -1);
- return -1;
- }
} else
- file->idata = fd;
+ file->idata = _GD_MakeTempFile(file->D, fd, file->name);
+ if (file->idata < 0) {
+ dreturn("%i", -1);
+ return -1;
+ }
+
file->edata = fdopen(file->idata, (mode & GD_FILE_WRITE) ? "rb+" : "rb");
if (file->edata == NULL) {
Index: src/encoding.c
===================================================================
diff --git a/trunk/getdata/src/encoding.c b/trunk/getdata/src/encoding.c
--- a/trunk/getdata/src/encoding.c (revision 830)
+++ b/trunk/getdata/src/encoding.c (working copy)
@@ -544,16 +544,13 @@
E->e->u.raw.file + 1, filebase, 1, 0))
{
; /* error already set */
- } else if ((temp_fd = _GD_MakeTempFile(D, D->fragment[fragment].dirfd,
- E->e->u.raw.file[1].name)) < 0)
- {
- _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[1].name, errno, NULL);
- } else if ((*enc->open)(temp_fd, E->e->u.raw.file + 1, swap,
+ } else if ((*enc->open)(D->fragment[fragment].dirfd,
E->e->u.raw.file + 1, swap,
GD_FILE_WRITE | GD_FILE_TEMP))
{
_GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[1].name, errno, NULL);
Index: src/gzip.c
===================================================================
diff --git a/trunk/getdata/src/gzip.c b/trunk/getdata/src/gzip.c
--- a/trunk/getdata/src/gzip.c (revision 830)
+++ b/trunk/getdata/src/gzip.c (working copy)
@@ -51,6 +51,8 @@
return 1;
}
gzmode = "r";
+ } else if (mode & GD_FILE_TEMP) {
+ file->idata = _GD_MakeTempFile(file->D, fd, file->name);
} else
file->idata = fd;
Index: src/raw.c
===================================================================
diff --git a/trunk/getdata/src/raw.c b/trunk/getdata/src/raw.c
--- a/trunk/getdata/src/raw.c (revision 830)
+++ b/trunk/getdata/src/raw.c (working copy)
@@ -34,9 +34,11 @@
file->idata = gd_OpenAt(file->D, fd, file->name, ((mode & GD_FILE_WRITE) ?
(O_RDWR | O_CREAT) : O_RDONLY) | O_BINARY, 0666);
- } else
- file->idata = fd;
+ } else {
+ file->idata = _GD_MakeTempFile(file->D, fd, file->name);
+ }
+
file->pos = 0;
file->mode = mode | GD_FILE_READ;
Index: src/sie.c
===================================================================
diff --git a/trunk/getdata/src/sie.c b/trunk/getdata/src/sie.c
--- a/trunk/getdata/src/sie.c (revision 830)
+++ b/trunk/getdata/src/sie.c (working copy)
@@ -40,14 +40,14 @@
if (!(mode & GD_FILE_TEMP)) {
fd = gd_OpenAt(file->D, fdin, file->name, ((mode & GD_FILE_WRITE) ?
(O_RDWR | O_CREAT) : O_RDONLY) | O_BINARY, 0666);
+ } else {
+ fd = _GD_MakeTempFile(file->D, fdin, file->name);
+ }
- if (fd < 0) {
- dreturn("%i", -1);
- return -1;
- }
- } else
- fd = fdin;
-
+ if (fd < 0) {
+ dreturn("%i", -1);
+ return -1;
+ }
stream = fdopen(fd, (mode & GD_FILE_WRITE) ? "rb+" : "rb");
if (stream == NULL) {
|