From 4ded6e352ee0fb5d96d2e1b9f051aac1f07b4886 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Mon, 20 Apr 2020 21:51:58 +0200 Subject: Rework group saving save / saveParent write back to the original group saveParent saves changes in child groups (openAsChild) by saving the top-most parent saveAs / saveAsOverwrite resembles the old save / saveOverwrite For all other saving methods, groups opend with openAsChild are saved as if there was no parent --- src/cc4group.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/cc4group.h') diff --git a/src/cc4group.h b/src/cc4group.h index c08bad8..8de4616 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -247,6 +247,7 @@ typedef struct { bool (*create)(CC4Group* const this); // opens a group or a normal folder on the filesystem; path may point to a directory inside a group; path "-" can be used to read the group from stdin + // if path points to a directory inside a group, saving behaves the same as for cc4group.openAsChild bool (*openExisting)(CC4Group* const this, const char* const path); // opens a group that is stored entirely in memory @@ -272,13 +273,22 @@ typedef struct { bool (*openWithReadCallback)(CC4Group* const this, CC4Group_ReadCallback const readCallback, void* const callbackArg, CC4Group_MemoryManagement const memoryManagement, CC4Group_ReadSetupCallback const initCallback, CC4Group_ReadSetupCallback const deinitCallback); + // saves the current in-memory state of the group as a compressed c4group to disk + // overwrites the group from which this instance was opened + // works only for groups opened using cc4group.openExisting (and not from stdin via "-") + bool (*save)(CC4Group* const this); + + // same as cc4group.save, but in case of a group created using cc4group.openAsChild, saves the top-most parent instead + // also applies to groups which have been opened using a path which is a subgroup of the actual group + bool (*saveParent)(CC4Group* const this); + // saves the current in-memory state of the group as a compressed c4group to disk // fails if the given path already exists; path "-" can be used to write the group to stdout - bool (*save)(CC4Group* const this, const char* const path); + bool (*saveAs)(CC4Group* const this, const char* const path); // same as save, except that an already existing group will be overwritten // be careful, any existing file will be overwritten in-place. if any error occurs after opening the target file (e.g. out of memory, a program or system crash), the previous contents will be lost - bool (*saveOverwrite)(CC4Group* const this, const char* const path); + bool (*saveAsOverwrite)(CC4Group* const this, const char* const path); // saves the compressed group file by writing it to the file descriptor // the file descriptor must have been opened with write access and must be in blocking mode (should be default if O_NONBLOCK is not specified) @@ -415,7 +425,10 @@ typedef struct { // the returned group will share most resources with its parent (the one passed as this) // the parent may be deleted anytime, but it will stay in memory until the child is deleted as well (using reference counting) // because both share most of their data, modifications of the child will affect the parent and the opposite direction is also possible if the modifications involve the subgroup - // saving through child groups is not implemented yet, it will result in an error + // all save methods except cc4group.save and cc4group.saveParent save the child groups contents as if it didn't have a parent at all + // cc4group.save refuses to save groups from cc4group.openAsChild + // cc4group.saveParent saves the top-most parent with cc4group.save in order to save the changes in the child to disk. this will also save modifications made inside the parent group... + // ...outside of this children CC4Group* (*openAsChild)(CC4Group* const this, const char* const path); } const CC4Group_API; -- cgit v1.2.3-54-g00ecf