Skip to content

Commit

Permalink
Preserve permissions when copying files
Browse files Browse the repository at this point in the history
  • Loading branch information
kesslern committed Mar 23, 2018
1 parent b9bc079 commit a825344
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ test:
./$(EXECFILE) $(TEST_RULES) $(TEST_DOTFILES) $(TEST_DEST_DIR); \
fi
diff $(DIFF_FLAGS) $(TEST_DEST_DIR) $(TEST_EXPECTED_DIR)

if [ ! -x "$(TEST_DEST_DIR)/binary_file" ]; then \
@echo "Expected binary_file to be executable."; \
exit 1; \
fi
@echo "*** All tests successfully passed. ***"

clean:
rm -f $(OBJS)
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ Many developers store their dotfiles in git repositories, allowing them to share
* Make string substitutions in files according to configuration files.
* Include or exclude chunks of files according to configuration file feature flags.
* Binary files are copied without templating.
* File permissions are preserved -- executable scripts will remain executable.

## Known Bugs
* File permissions are not preserved. This mostly affects executable scripts. After templating they must manually be set executable.

Please report any bugs, difficulties, or suggestions in the issue tracker.
I fixed all I could find. Please report any bugs, difficulties, or suggestions in the issue tracker.

### Planned Features
You tell me!
Expand Down
1 change: 1 addition & 0 deletions dottemplater.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int walker(const char *fpath, const struct stat *sb,
} else {
copy_file(fpath, dest_file);
}
copy_permission(fpath, dest_file);
}

free(dest_file);
Expand Down
Empty file modified test/dotfiles/binary_file
100644 → 100755
Empty file.
Empty file modified test/expected/binary_file
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,14 @@ void copy_file(const char *src, const char *dest)
close(input_file);
close(output_file);
}

void copy_permission(const char *src, const char *dest)
{
struct stat s;
stat(src, &s);

if (chmod(dest, s.st_mode) < 0) {
perror("chmod");
exit(1);
}
}
3 changes: 3 additions & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ bool is_binary_file(const char *fpath);

/** Copies a src file to a destination file.*/
void copy_file(const char *src, const char *dest);

/** Duplicates permissions on src to dest. */
void copy_permission(const char *src, const char *dest);

0 comments on commit a825344

Please sign in to comment.