summaryrefslogtreecommitdiffstats
path: root/src/cc4group.c
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2020-04-02 02:59:52 +0200
committerMarkus Mittendrein <git@maxmitti.tk>2020-04-02 02:59:52 +0200
commit327b9ad4985a1939826746c98b44957dd4ca59ce (patch)
tree953424b793bb0a701eb4bdbc548e976114718839 /src/cc4group.c
parent43b04d71d80d7bbc610eef1bce838cee4cf1631a (diff)
downloadcc4group-327b9ad4985a1939826746c98b44957dd4ca59ce.tar.gz
cc4group-327b9ad4985a1939826746c98b44957dd4ca59ce.zip
Add cc4group.extractSingleRename
Diffstat (limited to 'src/cc4group.c')
-rw-r--r--src/cc4group.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/cc4group.c b/src/cc4group.c
index 92dd784..c3454f8 100644
--- a/src/cc4group.c
+++ b/src/cc4group.c
@@ -1783,7 +1783,7 @@ static bool cc4group_extractEntry(CC4Group* const this, const C4GroupEntryData*
return success;
}
-static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryData* const root, const char* const targetPath)
+static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryData* const root, const char* const targetPath, bool const rename)
{
assert(root);
@@ -1797,11 +1797,14 @@ static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryDat
}
strcpy(tmpPath, targetPath);
- if(*targetPath != '\0')
+ if(!rename)
{
- strcat(tmpPath, "/");
+ if(*targetPath != '\0')
+ {
+ strcat(tmpPath, "/");
+ }
+ strcat(tmpPath, root->core.FileName);
}
- strcat(tmpPath, root->core.FileName);
bool success = true;
@@ -1823,7 +1826,7 @@ static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryDat
ForeachGroupEntry(children)
{
- if(!cc4group_extractChildren(this, &entry->value, tmpPath))
+ if(!cc4group_extractChildren(this, &entry->value, tmpPath, false))
{
success = false;
goto ret;
@@ -1854,7 +1857,7 @@ static bool cc4group_extractAll(CC4Group* const this, const char* const targetPa
{
assert(this);
- return cc4group_extractChildren(this, &this->root, targetPath);
+ return cc4group_extractChildren(this, &this->root, targetPath, false);
}
@@ -2017,7 +2020,21 @@ static bool cc4group_extractSingle(CC4Group* const this, const char* const entry
return false;
}
- return cc4group_extractChildren(this, entry, targetPath);
+ return cc4group_extractChildren(this, entry, targetPath, false);
+}
+
+static bool cc4group_extractSingleRename(CC4Group* const this, const char* const entryPath, const char* const targetPath)
+{
+ assert(this);
+ assert(targetPath);
+
+ const C4GroupEntryData* entry = cc4group_getFileOrDirectoryByPath(this, entryPath, true, NULL);
+ if(entry == NULL)
+ {
+ return false;
+ }
+
+ return cc4group_extractChildren(this, entry, targetPath, true);
}
static void* cc4group_mmappedFileManagementStart(void* const data, size_t const size, void* const arg)
@@ -3327,6 +3344,7 @@ CC4Group_API cc4group = {
.extractAll = cc4group_extractAll,
.extractSingle = cc4group_extractSingle,
+ .extractSingleRename = cc4group_extractSingleRename,
.getEntryInfo = cc4group_getEntryInfo,