Changeset: 8088507bd546 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8088507bd546
Modified Files:
gdk/gdk_heap.c
gdk/gdk_storage.c
Branch: default
Log Message:
Use mode flag "a" for create-if-not-exist without truncate-if-exist.
This is in GDKfdlocate and GDKfilelocate.
diffs (70 lines):
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -52,7 +52,7 @@ HEAPcreatefile(int farmid, size_t *maxsz
fn = path;
}
/* round up to multiple of GDK_mmap_pagesize */
- fd = GDKfdlocate(NOFARM, fn, "w+b", NULL);
+ fd = GDKfdlocate(NOFARM, fn, "ab+", NULL); /* create, no truncate */
if (fd >= 0) {
size_t size = (*maxsz + GDK_mmap_pagesize - 1) &
~(GDK_mmap_pagesize - 1);
if (size == 0)
@@ -346,7 +346,7 @@ HEAPextend(Heap *h, size_t size)
* to STORE_PRIV (copy-on-write memory mapped files),
* but if the heap file doesn't exist yet, the BAT is
* new and we can use STORE_MMAP */
- int fd = GDKfdlocate(h->farmid, nme, "r+b", ext);
+ int fd = GDKfdlocate(h->farmid, nme, "rb+", ext);
if (fd >= 0) {
assert(h->hasfile);
gdk_return rc = GDKextendf(fd, size, nme);
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -219,23 +219,37 @@ GDKfdlocate(int farmid, const char *nme,
nme = path;
}
- if (strchr(mode, 'w')) {
- flags |= O_CREAT | O_TRUNC;
+ switch (*mode) {
+ case 'r':
if (strchr(mode, '+')) {
flags |= O_RDWR;
} else {
- flags |= O_WRONLY;
+ flags |= O_RDONLY;
+ }
+ break;
+ case 'a':
+ if (strchr(mode, '+')) {
+ flags |= O_RDWR | O_CREAT;
+ } else {
+ flags |= O_WRONLY | O_CREAT;
}
- } else if (strchr(mode, '+')) {
- flags |= O_RDWR;
- } else {
- flags |= O_RDONLY;
+ break;
+ case 'w':
+ if (strchr(mode, '+')) {
+ flags |= O_RDWR | O_CREAT | O_TRUNC;
+ } else {
+ flags |= O_WRONLY | O_CREAT | O_TRUNC;
+ }
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
}
#ifdef O_BINARY
flags |= strchr(mode, 'b') ? O_BINARY : O_TEXT;
#endif
fd = MT_open(nme, flags);
- if (fd < 0 && *mode == 'w') {
+ if (fd < 0 && *mode != 'r') {
/* try to create the directory, in case that was the problem */
if (GDKcreatedir(nme) == GDK_SUCCEED) {
fd = MT_open(nme, flags);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]