Skip to content

Commit ba33258

Browse files
committed
read did not provide any data
1 parent 60a63c1 commit ba33258

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/FileSystems/FileSystemMemory.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,13 @@ class FileSystemMemory : public FileSystem {
169169
FS_LOGW("open: entry invalid: %s", path);
170170
return -1;
171171
}
172+
RegContentMemory* p_ref = (RegContentMemory*)mem_entry.content;
172173
// copy content, so that we can delete the entry.content when it is closed
173-
entry.content = new RegContentMemory();
174-
*entry.content = *mem_entry.content;
174+
RegContentMemory* p_new = new RegContentMemory();
175+
p_new->size = p_ref->size;
176+
p_new->data = p_ref->data;
177+
p_new->current_pos = 0;
178+
entry.content = p_new;
175179
return entry.fileID;
176180
}
177181

@@ -186,16 +190,20 @@ class FileSystemMemory : public FileSystem {
186190
if (size == 0) {
187191
return 0;
188192
}
193+
// If we did not find any content we return 0
189194
RegEntry &entry = DefaultRegistry.getEntry(fd);
190195
RegContentMemory *p_memory = getContent(entry);
191196
if (p_memory == nullptr) {
192197
FS_LOGW("No content for %s", entry.file_name);
193198
return 0;
194199
}
200+
// If we are at the end we return 0
195201
int pos = p_memory->current_pos;
196202
if(pos>=p_memory->size){
203+
FS_LOGD("=> read: pos=%d file-size=%d fd=%d -> %d", pos, p_memory->size, fd, 0);
197204
return 0;
198205
}
206+
// Copy requested data
199207
int len = min(size, p_memory->size - pos);
200208
p_memory->current_pos += len;
201209
memmove(data, p_memory->data + pos, len);

0 commit comments

Comments
 (0)