diff options
author | Jan Synacek <jsynacek@redhat.com> | 2014-04-23 12:52:16 +0200 |
---|---|---|
committer | Jan Synacek <jsynacek@redhat.com> | 2014-04-24 13:48:25 +0200 |
commit | 47f3990370bf8f2cba429fce53287fa4e67ce04e (patch) | |
tree | 558a68cc1e94bd44aaa1c9fbba4803404fdd9721 | |
parent | 799820bf4b9208f76b290213f501f2cf2a9735dc (diff) | |
download | openlmi-providers-47f3990370bf8f2cba429fce53287fa4e67ce04e.tar.gz openlmi-providers-47f3990370bf8f2cba429fce53287fa4e67ce04e.tar.xz openlmi-providers-47f3990370bf8f2cba429fce53287fa4e67ce04e.zip |
logicalfile: add support for symlink creation
-rw-r--r-- | src/logicalfile/LMI_SymbolicLinkProvider.c | 21 | ||||
-rw-r--r-- | src/logicalfile/LMI_UnixDirectoryProvider.c | 2 | ||||
-rw-r--r-- | src/logicalfile/file.c | 7 | ||||
-rw-r--r-- | src/logicalfile/file.h | 3 | ||||
-rw-r--r-- | src/logicalfile/test/test_basic.py | 21 |
5 files changed, 51 insertions, 3 deletions
diff --git a/src/logicalfile/LMI_SymbolicLinkProvider.c b/src/logicalfile/LMI_SymbolicLinkProvider.c index bab03d8..8060307 100644 --- a/src/logicalfile/LMI_SymbolicLinkProvider.c +++ b/src/logicalfile/LMI_SymbolicLinkProvider.c @@ -83,7 +83,25 @@ static CMPIStatus LMI_SymbolicLinkCreateInstance( const CMPIObjectPath* cop, const CMPIInstance* ci) { - CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); + CMPIStatus st = {.rc = CMPI_RC_OK}; + CMPIObjectPath *iop = CMGetObjectPath(ci, &st); + check_status(st); + st = lmi_check_required(_cb, cc, iop); + check_status(st); + + const char *path = get_string_property_from_instance(ci, "Name"); + const char *target = get_string_property_from_instance(ci, "TargetFile"); + + if (symlink(target, path) < 0) { + char errmsg[BUFLEN]; + char strerr[BUFLEN]; + snprintf(errmsg, BUFLEN, "Can't create symlink: %s pointing to %s (%s)", + path, target, + strerror_r(errno, strerr, BUFLEN)); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + + return CMReturnObjectPath(cr, iop); } static CMPIStatus LMI_SymbolicLinkModifyInstance( @@ -158,4 +176,5 @@ KONKRET_REGISTRATION( /* vi: set et: */ /* Local Variables: */ /* indent-tabs-mode: nil */ +/* c-basic-offset: 4 */ /* End: */ diff --git a/src/logicalfile/LMI_UnixDirectoryProvider.c b/src/logicalfile/LMI_UnixDirectoryProvider.c index 38799c1..91211c7 100644 --- a/src/logicalfile/LMI_UnixDirectoryProvider.c +++ b/src/logicalfile/LMI_UnixDirectoryProvider.c @@ -17,8 +17,6 @@ * * Authors: Jan Synacek <jsynacek@redhat.com> */ -#include <errno.h> -#include <unistd.h> #include <konkret/konkret.h> #include "LMI_UnixDirectory.h" #include "file.h" diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c index 78dddd3..f2666c3 100644 --- a/src/logicalfile/file.c +++ b/src/logicalfile/file.c @@ -150,6 +150,13 @@ const char *get_string_property_from_op(const CMPIObjectPath *o, const char *pro return KChars(d.value.string); } +const char *get_string_property_from_instance(const CMPIInstance *i, const char *prop) +{ + CMPIData d; + d = CMGetProperty(i, prop, NULL); + return KChars(d.value.string); +} + CMPIStatus check_assoc_class( const CMPIBroker *cb, const char *namespace, diff --git a/src/logicalfile/file.h b/src/logicalfile/file.h index 36ff8fa..d2f573b 100644 --- a/src/logicalfile/file.h +++ b/src/logicalfile/file.h @@ -30,6 +30,8 @@ #include <konkret/konkret.h> #include <assert.h> #include <libudev.h> +#include <errno.h> +#include <unistd.h> #include "LMI_DataFile.h" #include "LMI_UnixDeviceFile.h" #include "LMI_SymbolicLink.h" @@ -129,6 +131,7 @@ int get_class_from_path(const char *, char *); CMPIStatus get_fsinfo_from_stat(const CMPIBroker *, const struct stat *, const char *, char **, char **); CMPIStatus get_fsinfo_from_path(const CMPIBroker *, const char *, char **, char **); const char *get_string_property_from_op(const CMPIObjectPath *, const char *); +const char *get_string_property_from_instance(const CMPIInstance *, const char *); CMPIStatus check_assoc_class(const CMPIBroker *, const char *, const char *, const char *); CMPIStatus stat_logicalfile_and_fill(const CMPIBroker *, logicalfile_t *, mode_t, const char *); void _dump_objectpath(const CMPIObjectPath *); diff --git a/src/logicalfile/test/test_basic.py b/src/logicalfile/test/test_basic.py index 3047f9e..b5871fb 100644 --- a/src/logicalfile/test/test_basic.py +++ b/src/logicalfile/test/test_basic.py @@ -460,6 +460,27 @@ class TestLogicalFile(LogicalFileTestBase): rmdir, '/cant/remove/me') + def test_create_symlink(self): + def create_symlink(target, path): + cop = self.cop.copy() + cop['Name'] = path + cop['TargetFile'] = path + inst = pywbem.CIMInstance('LMI_SymbolicLink', cop.keybindings) + self.wbemconnection.CreateInstance(inst) + + target = self.files['data']['path'] + name = self.testdir + '/target-symlink' + + try: + create_symlink(target, name) + except pywbem.CIMError as pe: + self.fail(pe[1]) + + self.assertRaises(pywbem.CIMError, + create_symlink, + target, + name) + # for now, this test just checks if FSName, FSCreationClassName, # CreationClassName and LFCreationClassName are properly ignored; empty # strings are used, since they should represent "ignored" pretty well |