diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-03-04 19:50:53 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-03-04 19:50:53 +0200 |
commit | c9652e54a0fe2918c0ce7e70e8a0cba8d5f2e201 (patch) | |
tree | 0011879a1ad1c5fa8d3e349d185ec15a60cd31e8 | |
parent | 6395c06c23c18a615b75f886e29bcae5eb01b024 (diff) | |
download | vcsync-c9652e54a0fe2918c0ce7e70e8a0cba8d5f2e201.tar.gz vcsync-c9652e54a0fe2918c0ce7e70e8a0cba8d5f2e201.tar.bz2 |
Implement the unlink action.
-rw-r--r-- | src/doinstrc.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/doinstrc.c b/src/doinstrc.c index a7be214..da4682b 100644 --- a/src/doinstrc.c +++ b/src/doinstrc.c @@ -148,6 +148,44 @@ kwf_link(struct stmt_env *env) return 0; } +int +kwf_unlink(struct stmt_env *env) +{ + struct stat st; + char *filename; + + if (checkargs(env, 2)) + return 1; + + filename = env->argv[1]; + if (!valid_file_name(filename)) { + diag(LOG_ERR, "%s:%u: %s: illegal filename", + env->filename, env->line, env->argv[1]); + return 1; + } + + if (stat(filename, &st)) { + if (errno != ENOENT) + diag(LOG_NOTICE, "unlink: cannot stat %s: %s", + filename, strerror(errno)); + return 1; + } + if (!S_ISLNK(st.st_mode) && + strcmp(filename + strlen(filename) - sizeof(HTACCESS_FILE) + 1, + HTACCESS_FILE)) { + diag(LOG_ERR, "won't unlink %s", filename); + return 1; + } + + if (unlink(filename)) { + diag(LOG_ERR, "can't unlink %s: %s", + filename, strerror(errno)); + return 1; + } + + return 0; +} + /* Syntax: chmod MODE FILE Function: change mode of a file */ @@ -190,6 +228,7 @@ kwf_chmod(struct stmt_env *env) static struct keyword kwtab[] = { { "link", KW_HANDLER, { handler: kwf_link } }, + { "unlink", KW_HANDLER, { handler: kwf_unlink } }, { "chmod", KW_HANDLER, { handler: kwf_chmod } }, { "xbithack", KW_TEXT, { text: "Options +IncludesNOEXEC\n" "XBitHack On" } }, |