--------------------- PatchSet 1131 Date: 2001/01/06 19:29:03 Author: hno Branch: nt-2_4 Tag: (none) Log: Ported changes from nt-2_3 Members: src/fs/ufs/store_dir_ufs.c:1.4.2.2->1.4.2.2.2.1 Index: squid/src/fs/ufs/store_dir_ufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/store_dir_ufs.c,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.2.2.1 diff -u -r1.4.2.2 -r1.4.2.2.2.1 --- squid/src/fs/ufs/store_dir_ufs.c 6 Jan 2001 13:32:46 -0000 1.4.2.2 +++ squid/src/fs/ufs/store_dir_ufs.c 6 Jan 2001 19:29:03 -0000 1.4.2.2.2.1 @@ -218,7 +218,11 @@ } else { fatalf("Swap directory %s is not a directory.", path); } +#ifdef _SQUID_MSWIN_ + } else if (0 != CreateDirectory(path, NULL)) { +#else } else if (0 == mkdir(path, 0755)) { +#endif debug(20, should_exist ? 1 : 3) ("%s created\n", path); created = 1; } else { @@ -867,6 +871,12 @@ fatal("storeUfsDirCloseTmpSwapLog: unlink failed"); } #endif +#ifdef _SQUID_MSWIN_ + if (unlink(swaplog_path) < 0) { + debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); + fatal("storeUfsDirCloseTmpSwapLog: unlink failed"); + } +#endif if (xrename(new_path, swaplog_path) < 0) { fatal("storeUfsDirCloseTmpSwapLog: rename failed"); } @@ -911,7 +921,11 @@ } ufsinfo->swaplog_fd = fd; /* open a read-only stream of the old log */ +#ifdef _SQUID_MSWIN_ + fp = fopen(swaplog_path, "rb"); +#else fp = fopen(swaplog_path, "r"); +#endif if (fp == NULL) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); @@ -999,6 +1013,9 @@ static void storeUfsDirWriteCleanEntry(SwapDir * sd, const StoreEntry * e) { +#ifdef _SQUID_MSWIN_ + FILE *fbuf; +#endif storeSwapLogData s; static size_t ss = sizeof(storeSwapLogData); struct _clean_state *state = sd->log.clean.state; @@ -1017,7 +1034,13 @@ state->outbuf_offset += ss; /* buffered write */ if (state->outbuf_offset + ss > CLEAN_BUF_SZ) { +#ifdef _SQUID_MSWIN_ + fbuf = fd_table[state->fd].fbuf; + fwrite(state->outbuf, 1, state->outbuf_offset, fbuf); + if (ferror(fbuf) || feof(fbuf)) { +#else if (write(state->fd, state->outbuf, state->outbuf_offset) < 0) { +#endif debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", state->new, xstrerror()); debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile not replaced.\n"); @@ -1035,6 +1058,9 @@ static void storeUfsDirWriteCleanDone(SwapDir * sd) { +#ifdef _SQUID_MSWIN_ + FILE *fbuf; +#endif int fd; struct _clean_state *state = sd->log.clean.state; if (NULL == state) @@ -1042,7 +1068,13 @@ if (state->fd < 0) return; state->walker->Done(state->walker); +#ifdef _SQUID_MSWIN_ + fbuf = fd_table[state->fd].fbuf; + fwrite(state->outbuf, 1, state->outbuf_offset, fbuf); + if (ferror(fbuf) || feof(fbuf)) { +#else if (write(state->fd, state->outbuf, state->outbuf_offset) < 0) { +#endif debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", state->new, xstrerror()); debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile " @@ -1068,6 +1100,13 @@ debug(50, 0) ("storeDirWriteCleanLogs: unlinkd failed: %s, %s\n", xstrerror(), state->cur); #endif +#ifdef _SQUID_MSWIN_ + file_close(state->fd); + state->fd = -1; + if (unlink(state->cur) < 0) + debug(50, 0) ("storeDirWriteCleanLogs: unlinkd failed: %s, %s\n", + xstrerror(), state->cur); +#endif xrename(state->new, state->cur); } /* touch a timestamp file if we're not still validating */ @@ -1169,7 +1208,11 @@ if (dp == NULL) { if (errno == ENOENT) { debug(36, 0) ("storeDirClean: WARNING: Creating %s\n", p1); +#ifdef _SQUID_MSWIN_ + if (CreateDirectory(p1, NULL) == 0) +#else if (mkdir(p1, 0777) == 0) +#endif return 0; } debug(50, 0) ("storeDirClean: %s: %s\n", p1, xstrerror());