Skip to content

Commit

Permalink
passsed all tests. ready for use now
Browse files Browse the repository at this point in the history
  • Loading branch information
kmxz committed Aug 15, 2015
1 parent 4a94f35 commit 1cb719f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
**This project is unfinished and NOT usable yet.**

overlayfs-tools
========

Expand Down
9 changes: 4 additions & 5 deletions logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,20 @@ int merge_d(const char *lower_path, const char* upper_path, const size_t lower_r
}
return 0; // children must be recursed, and directory itself does not need to be printed
}
} else { // other types of files
} else {
command(script_stream, "rm %", lower_path);
}
}
*fts_instr = FTS_SKIP;
return command(script_stream, "mv % %", upper_path, lower_path);
return command(script_stream, "mv -T % %", upper_path, lower_path);
}

int merge_dp(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, bool verbose, FILE* script_stream, int *fts_instr) {
// if children ARE visited, delete the directory
if (lower_status != NULL) {
if (file_type(lower_status) == S_IFDIR) {
bool opaque = false;
if (is_opaquedir(upper_path, &opaque) < 0) { return -1; }
if (!opaque) {
if (!opaque) { // delete the directory: it should be empty already
return command(script_stream, "rmdir %", upper_path);
}
}
Expand All @@ -326,7 +325,7 @@ int merge_dp(const char *lower_path, const char* upper_path, const size_t lower_
}

int merge_f_sl(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, bool verbose, FILE* script_stream, int *fts_instr) {
return command(script_stream, "mv % %", upper_path, lower_path);
return command(script_stream, "rm -rf %", lower_path) || command(script_stream, "mv -T % %", upper_path, lower_path);
}

int merge_whiteout(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, bool verbose, FILE* script_stream, int *fts_instr) {
Expand Down
5 changes: 4 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,24 @@ int main(int argc, char *argv[]) {

if (optind == argc - 1) {
int out;
char filename_template[] = "overylay-toolsXXXXXX.sh";
char filename_template[] = "overlay-tools-XXXXXX.sh";
FILE *script = NULL;
if (strcmp(argv[optind], "diff") == 0) {
out = diff(lower, upper, verbose);
} else if (strcmp(argv[optind], "vacuum") == 0) {
script = create_shell_script(filename_template);
if (script == NULL) { fprintf(stderr, "Script file cannot be created."); return EXIT_FAILURE; }
out = vacuum(lower, upper, verbose, script);
} else if (strcmp(argv[optind], "merge") == 0) {
script = create_shell_script(filename_template);
if (script == NULL) { fprintf(stderr, "Script file cannot be created."); return EXIT_FAILURE; }
out = merge(lower, upper, verbose, script);
} else {
fprintf(stderr, "Action not supported.\n");
goto see_help;
}
if (script != NULL) {
printf("The script %s is created. Run the script to do the actual work please. Remember to run it when the OverlayFS is not mounted.\n", filename_template);
fclose(script);
}
if (out) {
Expand Down
6 changes: 3 additions & 3 deletions sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FILE* create_shell_script(char *tmp_path_buffer) {
fprintf(f, "set -x\n");
time_t rawtime;
time (&rawtime);
fprintf(f, "# This sheel script is generated by overlayfs-tools on %s.\n", ctime (&rawtime));
fprintf(f, "# This shell script is generated by overlayfs-tools on %s\n", ctime (&rawtime));
return f;
}

Expand All @@ -39,12 +39,12 @@ int command(FILE *output, const char *command_format, ...) {
for (size_t i = 0; command_format[i] != '\0'; i++) {
if (command_format[i] == '%') {
const char *s = va_arg(arg, char *);
if (quote(s, output) < 1) { return -1; }
if (quote(s, output) < 0) { return -1; }
} else {
if (fputc(command_format[i], output) == EOF) { return -1; }
}
}
va_end(arg);
if (fputc('\n', output) == EOF) { return -1; }
return 0;
}
}
Binary file modified test_cases/upper.tar
Binary file not shown.

0 comments on commit 1cb719f

Please sign in to comment.