Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Siguza committed Jan 13, 2019
0 parents commit 8241505
Show file tree
Hide file tree
Showing 9 changed files with 1,118 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
/imobax
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
VERSION = 1.0.0
TARGET = imobax
SRCDIR = src
FLAGS ?= -Wall -O3 -DVERSION=$(VERSION) -DTIMESTAMP="`date +'%d. %B %Y %H:%M:%S'`" -flto -lsqlite3 $(CFLAGS)

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(SRCDIR)/*.c
$(CC) -o $@ $^ $(FLAGS)

clean:
rm -f $(TARGET)
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# imobax

The **i**OS **Mo**bile **Ba**ckup **X**tractor.
It extracts backups... and stuff.

Binary releases for macOS: [here](https://github.com/Siguza/imobax/releases).

### Building

As always:

make

### Usage

Usage:
./imobax [-f] [-i] [-l] source-dir [target-dir]

Options:
-f Force overwriting of existing files
-i Ignore missing files in backup
-l List contents only, write nothing

### License

[MPL2](https://github.com/Siguza/imobax/blob/master/LICENSE) with Exhibit B.
97 changes: 97 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* Copyright (c) 2019 Siguza
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
**/

#include <errno.h>
#include <stdbool.h>
#include <stdlib.h> // free
#include <string.h> // strdup
#include <unistd.h> // faccessat, F_OK
#include <sys/stat.h> // mkdirat

#include "common.h"

int mkdirat_recursive(int fd, const char *path, bool only_parent)
{
int retval = -1;
char *str = NULL;

if(path[0] == '\0')
{
LOG("mkdirat_recursive: bad argument");
goto out;
}

str = strdup(path);
if(!str)
{
ERRNO("strdup(%s)", path);
goto out;
}

for(size_t i = 1; 1; ++i)
{
bool doit = false,
flip = false,
end = false;
if(str[i] == '/')
{
doit = true;
flip = true;
}
else if(str[i] == '\0')
{
if(!only_parent)
{
doit = true;
}
end = true;
}

if(doit)
{
if(flip)
{
str[i] = '\0';
}

if(faccessat(fd, str, F_OK, 0) != 0)
{
if(errno != ENOENT)
{
ERRNO("access(%s)", str);
break;
}
else
{
if(mkdirat(fd, str, 0755) != 0)
{
ERRNO("mkdir(%s)", str);
break;
}
}
}

if(flip)
{
str[i] = '/';
}
}

if(end)
{
break;
}
}

retval = 0;
out:;
if(str) free(str);
return retval;
}
27 changes: 27 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright (c) 2019 Siguza
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
**/

#ifndef COMMON_H
#define COMMON_H

#include <errno.h>
#include <stdbool.h>
#include <stdio.h> // fprintf, stderr
#include <string.h> // strerror

#define LOG(str, args...) do { fprintf(stderr, str "\n", ##args); } while(0)
#define ERRNO(str, args...) LOG(str ": %s", ##args, strerror(errno))

#define STRINGIFX(x) #x
#define STRINGIFY(x) STRINGIFX(x)

int mkdirat_recursive(int fd, const char *path, bool only_parent);

#endif
Loading

0 comments on commit 8241505

Please sign in to comment.