Discussion:
[Polipo-users] rewriteEntry for WIN32
Gabriel Klyber
2016-01-23 07:39:23 UTC
Permalink
This is not clean and has not been tested, but is a possible
implementation of rewriteEntry for WIN32:

@@ -1324,12 +1329,38 @@
int buf_is_chunk, bufsize;
int offset;

+#ifdef WIN32
+ /* malloc/free might be better, but there are a lot of error
return cases to cover */
+ char wintmp[1024];
+
+ strcpy(wintmp, object->disk_entry->filename);
+ strcat(wintmp, ".1");
+
+ close(object->disk_entry->fd);
+ object->disk_entry->fd = -1;
+ rename(object->disk_entry->filename, wintmp);
+
+ /* This is not clean, but makes destroyDiskEntry function as expected */
+ entry->object->flags &= ~OBJECT_DISK_ENTRY_COMPLETE;
+ object->disk_entry->fd = open(object->disk_entry->filename,
O_RDWR | O_CREAT | O_EXCL | O_BINARY,
+ diskCacheFilePermissions);
+ if(object->disk_entry->fd < 0) {
+ do_log_error(L_ERROR, errno, "Couldn't create file %s", wintmp);
+ return -1;
+ }
+
+ fd = open(wintmp, O_RDONLY | O_BINARY);
+ if(fd < 0) {
+ do_log_error(L_ERROR, errno, "Couldn't open file %s", wintmp);
+ return -1;
+ }
+#else
fd = dup(object->disk_entry->fd);
if(fd < 0) {
do_log_error(L_ERROR, errno, "Couldn't duplicate file descriptor");
return -1;
}
-
+#endif
rc = destroyDiskEntry(object, 1);
if(rc < 0) {
close(fd);
@@ -1392,6 +1423,9 @@
if(object->length >= 0 && entry->size == object->length)
object->flags |= OBJECT_DISK_ENTRY_COMPLETE;
close(fd);
+#ifdef WIN32
+ unlink(wintmp);
+#endif
if(buf_is_chunk)
dispose_chunk(buf);
else
Juliusz Chroboczek
2016-01-30 15:05:51 UTC
Permalink
Post by Gabriel Klyber
This is not clean and has not been tested,
This is not very helpful.

Loading...