Beispiel #1
0
        public void TestSplitShareNameAndSubPath()
        {
            String subPath;

            Assert.AreEqual(null, NfsPath.SplitShareNameAndSubPath(null, out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual(null, NfsPath.SplitShareNameAndSubPath("", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual(null, NfsPath.SplitShareNameAndSubPath("/", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("a", NfsPath.SplitShareNameAndSubPath("a", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("a", NfsPath.SplitShareNameAndSubPath("/a", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("a", NfsPath.SplitShareNameAndSubPath("a/", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("a", NfsPath.SplitShareNameAndSubPath("/a/", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("sharename", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("/sharename", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("sharename/", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("/sharename/", out subPath));
            Assert.AreEqual(null, subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("sharename/a", out subPath));
            Assert.AreEqual("a", subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("sharename/a/", out subPath));
            Assert.AreEqual("a", subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("sharename/a", out subPath));
            Assert.AreEqual("a", subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("/sharename/a/", out subPath));
            Assert.AreEqual("a", subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("/sharename/a/b", out subPath));
            Assert.AreEqual("a/b", subPath);

            Assert.AreEqual("sharename", NfsPath.SplitShareNameAndSubPath("/sharename/a/b/", out subPath));
            Assert.AreEqual("a/b", subPath);
        }
        public Nfs3Procedure.Status TryGetDirectory(String shareDirectoryName, out RootShareDirectory rootShareDirectory, out ShareObject shareDirectoryObject)
        {
            String subPath;
            String rootShareName = NfsPath.SplitShareNameAndSubPath(shareDirectoryName, out subPath);

            if (rootShareName == null)
            {
                rootShareDirectory   = null;
                shareDirectoryObject = null;
                return(Nfs3Procedure.Status.ErrorInvalidArgument);
            }

            Nfs3Procedure.Status status = TryGetRootSharedDirectory(rootShareName, out rootShareDirectory);
            if (status != Nfs3Procedure.Status.Ok)
            {
                shareDirectoryObject = null; return(status);
            }
            if (rootShareDirectory == null)
            {
                shareDirectoryObject = null; return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
            }

            if (subPath == null)
            {
                shareDirectoryObject = rootShareDirectory.shareObject;
            }
            else
            {
                String localPathAndName = PlatformPath.LocalCombine(rootShareDirectory.localShareDirectory, subPath);

                status = TryGetSharedObject(localPathAndName, subPath, out shareDirectoryObject);
                if (status != Nfs3Procedure.Status.Ok)
                {
                    return(status);
                }
                if (shareDirectoryObject == null)
                {
                    return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
                }

                shareDirectoryObject.RefreshFileAttributes(permissions);
            }
            return(Nfs3Procedure.Status.Ok);
        }