diff options
author | jkh <jkh@FreeBSD.org> | 1997-07-01 06:13:51 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1997-07-01 06:13:51 +0000 |
commit | ee55475a0f2a0c7391240ed7c9adc2b5a6e10a94 (patch) | |
tree | 0bc137577fb61dd8c8d58f35374873f1f35c4526 /usr.sbin/pkg_install/lib/file.c | |
parent | 3f044120cdb6253359462b5085756fca82a23d1c (diff) | |
download | FreeBSD-src-ee55475a0f2a0c7391240ed7c9adc2b5a6e10a94.zip FreeBSD-src-ee55475a0f2a0c7391240ed7c9adc2b5a6e10a94.tar.gz |
Change the naming conventions for preserve'd files and also document
the option in pkg_create. Now preserved files start with a . and are
named .<filename>.<pkgname>.backup so that their purpose is more clear.
Note that just using the preserve option without proper pkg_deps
is also foolish since packages being deleted in the incorrect order with
preserve on can generate some odd results.
Diffstat (limited to 'usr.sbin/pkg_install/lib/file.c')
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 6a2e746..2748235 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id$"; +static const char *rcsid = "$Id: file.c,v 1.27 1997/02/22 16:09:47 peter Exp $"; #endif /* @@ -338,6 +338,40 @@ fileGetContents(char *fname) return contents; } +/* Takes a filename and package name, returning (in "try") the canonical "preserve" + * name for it. + */ +Boolean +make_preserve_name(char *try, int max, char *name, char *file) +{ + int len, i; + + if ((len = strlen(file)) == 0) + return FALSE; + else + i = len - 1; + strncpy(try, file, max); + if (try[i] == '/') /* Catch trailing slash early and save checking in the loop */ + --i; + for (; i; i--) { + if (try[i] == '/') { + try[i + 1]= '.'; + strncpy(&try[i + 2], &file[i + 1], max - i - 2); + break; + } + } + if (!i) { + try[0] = '.'; + strncpy(try + 1, file, max - 1); + } + /* I should probably be called rude names for these inline assignments */ + strncat(try, ".", max -= strlen(try)); + strncat(try, name, max -= strlen(name)); + strncat(try, ".", max--); + strncat(try, "backup", max -= 6); + return TRUE; +} + /* Write the contents of "str" to a file */ void write_file(char *name, char *str) @@ -347,7 +381,7 @@ write_file(char *name, char *str) fp = fopen(name, "w"); if (!fp) - barf("Can't fopen '%s' for writing.", name); + barf("Cannot fopen '%s' for writing.", name); len = strlen(str); if (fwrite(str, 1, len, fp) != len) barf("Short fwrite on '%s', tried to write %d bytes.", name, len); @@ -365,7 +399,7 @@ copy_file(char *dir, char *fname, char *to) else snprintf(cmd, FILENAME_MAX, "cp -p -r %s/%s %s", dir, fname, to); if (vsystem(cmd)) - barf("Couldn't perform '%s'", cmd); + barf("Could not perform '%s'", cmd); } void @@ -378,7 +412,7 @@ move_file(char *dir, char *fname, char *to) else snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to); if (vsystem(cmd)) - barf("Couldn't perform '%s'", cmd); + barf("Could not perform '%s'", cmd); } /* @@ -408,7 +442,7 @@ copy_hierarchy(char *dir, char *fname, Boolean to) printf("Using '%s' to copy trees.\n", cmd); #endif if (system(cmd)) - barf("copy_file: Couldn't perform '%s'", cmd); + barf("copy_file: Could not perform '%s'", cmd); } /* Unpack a tar file */ |