nfs_symlink: Fix it so we can create symlinks in the current directory
Fix a bug in hte symlink code that required that linkname contained at least one path component and thus prevented us from creating symlinks in the current directory. Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>libnfs-4.0.0-vitalif
parent
8fa13b3a90
commit
ea94d4e3a6
25
lib/nfs3.c
25
lib/nfs3.c
|
@ -1542,7 +1542,20 @@ nfs3_symlink_async(struct nfs_context *nfs, const char *target,
|
|||
return -1;
|
||||
}
|
||||
|
||||
symlink_data->linkparent = strdup(linkname);
|
||||
symlink_data->linkobject = strdup(linkname);
|
||||
/* Do we have a path ? */
|
||||
ptr = strrchr(symlink_data->linkobject, '/');
|
||||
if (ptr == NULL) {
|
||||
/* pass this as NULL ? */
|
||||
symlink_data->linkparent = strdup("");
|
||||
} else {
|
||||
*ptr = 0;
|
||||
symlink_data->linkparent = symlink_data->linkobject;
|
||||
|
||||
ptr++;
|
||||
symlink_data->linkobject = strdup(ptr);
|
||||
}
|
||||
|
||||
if (symlink_data->linkparent == NULL) {
|
||||
nfs_set_error(nfs, "Out of memory, failed to allocate "
|
||||
"mode buffer for new path");
|
||||
|
@ -1550,16 +1563,6 @@ nfs3_symlink_async(struct nfs_context *nfs, const char *target,
|
|||
return -1;
|
||||
}
|
||||
|
||||
ptr = strrchr(symlink_data->linkparent, '/');
|
||||
if (ptr == NULL) {
|
||||
nfs_set_error(nfs, "Invalid path \"%s\"", linkname);
|
||||
free_nfs_symlink_data(symlink_data);
|
||||
return -1;
|
||||
}
|
||||
*ptr = 0;
|
||||
ptr++;
|
||||
|
||||
symlink_data->linkobject = strdup(ptr);
|
||||
if (symlink_data->linkobject == NULL) {
|
||||
nfs_set_error(nfs, "Out of memory, failed to allocate "
|
||||
"mode buffer for new path");
|
||||
|
|
|
@ -27,12 +27,13 @@
|
|||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libnfs.h"
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: prog-symlink <url> <target> <link>\n");
|
||||
fprintf(stderr, "Usage: prog-symlink <url> <cwd> <target> <link>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,7 @@ int main(int argc, char *argv[])
|
|||
int ret = 0;
|
||||
char buf[1024];
|
||||
|
||||
if (argc != 4) {
|
||||
if (argc != 5) {
|
||||
usage();
|
||||
}
|
||||
|
||||
|
@ -66,7 +67,14 @@ int main(int argc, char *argv[])
|
|||
goto finished;
|
||||
}
|
||||
|
||||
if (nfs_symlink(nfs, argv[2], argv[3])) {
|
||||
if (nfs_chdir(nfs, argv[2]) != 0) {
|
||||
fprintf(stderr, "Failed to chdir to \"%s\" : %s\n",
|
||||
argv[2], nfs_get_error(nfs));
|
||||
ret = 1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (nfs_symlink(nfs, argv[3], argv[4])) {
|
||||
fprintf(stderr, "Failed to create symlink: %s\n",
|
||||
nfs_get_error(nfs));
|
||||
ret = 1;
|
||||
|
@ -75,17 +83,17 @@ int main(int argc, char *argv[])
|
|||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (nfs_readlink(nfs, argv[3], buf, sizeof(buf))) {
|
||||
if (nfs_readlink(nfs, argv[4], buf, sizeof(buf))) {
|
||||
fprintf(stderr, "Failed to read symlink: %s\n",
|
||||
nfs_get_error(nfs));
|
||||
ret = 1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (strcmp(argv[2], buf)) {
|
||||
if (strcmp(argv[3], buf)) {
|
||||
fprintf(stderr, "Symlink target did not read back correctly."
|
||||
"Expected \"%s\" Got \"%s\"\n",
|
||||
buf, argv[2]);
|
||||
buf, argv[3]);
|
||||
ret = 1;
|
||||
goto finished;
|
||||
}
|
||||
|
|
|
@ -6,21 +6,67 @@ echo "basic symlink test"
|
|||
|
||||
start_share
|
||||
|
||||
mkdir "${TESTDIR}/subdir"
|
||||
mkdir "${TESTDIR}/subdir2"
|
||||
|
||||
echo -n "Create a symlink from a root path (absolute) ... "
|
||||
./prog_symlink "${TESTURL}/" kangabanga /symlink || failure
|
||||
./prog_symlink "${TESTURL}/" "." kangabanga /abslink || failure
|
||||
success
|
||||
|
||||
echo -n "Verify the link ... "
|
||||
ls -l "${TESTDIR}/symlink" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
ls -l "${TESTDIR}/abslink" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Create a symlink from a root path (relative) ... "
|
||||
./prog_symlink "${TESTURL}/" "." kangabanga rellink || failure
|
||||
success
|
||||
|
||||
echo -n "Verify the link ... "
|
||||
ls -l "${TESTDIR}/rellink" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Create a symlink from a nested path (absolute) ... "
|
||||
mkdir "${TESTDIR}/subdir"
|
||||
./prog_symlink "${TESTURL}/" kangabanga /subdir/symlink || failure
|
||||
./prog_symlink "${TESTURL}/" "." kangabanga /subdir/abslink || failure
|
||||
success
|
||||
|
||||
echo -n "Verify the link ... "
|
||||
ls -l "${TESTDIR}/subdir/symlink" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
ls -l "${TESTDIR}/subdir/abslink" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Create a symlink from a nested path (relative) ... "
|
||||
./prog_symlink "${TESTURL}/" "." kangabanga subdir/rellink || failure
|
||||
success
|
||||
|
||||
echo -n "Verify the link ... "
|
||||
ls -l "${TESTDIR}/subdir/rellink" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Create a symlink from a nested path (relative) ... "
|
||||
./prog_symlink "${TESTURL}/" "/subdir" kangabanga locallink || failure
|
||||
success
|
||||
|
||||
echo -n "Verify the link ... "
|
||||
ls -l "${TESTDIR}/subdir/locallink" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Create a symlink in a parent directory (relative) ... "
|
||||
./prog_symlink "${TESTURL}/" "/subdir" kangabanga ../link3 || failure
|
||||
success
|
||||
|
||||
echo -n "Verify the link ... "
|
||||
ls -l "${TESTDIR}/link3" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Create a symlink in a different directory (relative) ... "
|
||||
./prog_symlink "${TESTURL}/" "/subdir" kangabanga ../subdir2/link4 || failure
|
||||
success
|
||||
|
||||
echo -n "Verify the link ... "
|
||||
ls -l "${TESTDIR}/subdir2/link4" | egrep "\-> kangabanga$" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Create a symlink outside the share (relative) ... "
|
||||
./prog_symlink "${TESTURL}/" "/subdir" kangabanga ../../link5 2>/dev/null && failure
|
||||
success
|
||||
|
||||
stop_share
|
||||
|
|
Loading…
Reference in New Issue