Exemple #1
0
        public void DeleteFile(string FileFullName)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            if (_MountProtocolV2 == null)
            {
                throw new NFSMountConnectionException("NFS Device not connected!");
            }

            string ParentDirectory = System.IO.Path.GetDirectoryName(FileFullName);
            string FileName        = System.IO.Path.GetFileName(FileFullName);

            NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory);

            ItemOperationArguments dpArgDelete = new ItemOperationArguments();

            dpArgDelete.Directory = new NFSHandle(ParentItemAttributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION);
            dpArgDelete.Name      = new Name(FileName);

            NFSStats Status = (NFSStats)_ProtocolV2.NFSPROC_REMOVE(dpArgDelete);

            if (Status != NFSStats.NFS_OK)
            {
                ExceptionHelpers.ThrowException(Status);
            }
        }
Exemple #2
0
        public void DeleteFile(string FileFullName)
        {
            if (_ProtocolV3 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            if (_MountProtocolV3 == null)
            {
                throw new NFSMountConnectionException("NFS Device not connected!");
            }

            string ParentDirectory = System.IO.Path.GetDirectoryName(FileFullName);
            string FileName        = System.IO.Path.GetFileName(FileFullName);

            NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory);

            ItemOperationArguments dpArgDelete = new ItemOperationArguments();

            dpArgDelete.Directory = new NFSHandle(ParentItemAttributes.Handle, V3.RPC.NFSv3Protocol.NFS_V3);
            dpArgDelete.Name      = new Name(FileName);

            ResultObject <RemoveAccessOK, RemoveAccessFAIL> pRemoveRes =
                _ProtocolV3.NFSPROC3_REMOVE(dpArgDelete);

            if (pRemoveRes == null || pRemoveRes.Status != NFSStats.NFS_OK)
            {
                if (pRemoveRes == null)
                {
                    throw new NFSGeneralException("NFSPROC3_REMOVE: failure");
                }

                ExceptionHelpers.ThrowException(pRemoveRes.Status);
            }
        }
Exemple #3
0
        public NFSAttributes GetItemAttributes(String ItemFullName, bool ThrowExceptionIfNotFound = true)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            if (_MountProtocolV2 == null)
            {
                throw new NFSMountConnectionException("NFS Device not connected!");
            }

            NFSAttributes attributes = null;

            if (String.IsNullOrEmpty(ItemFullName))
            {
                ItemFullName = ".";
            }

            NFSHandle currentItem = _RootDirectoryHandleObject;

            String[] PathTree = ItemFullName.Split(@"\".ToCharArray());

            for (int pC = 0; pC < PathTree.Length; pC++)
            {
                ItemOperationArguments dpDrArgs = new ItemOperationArguments();
                dpDrArgs.Directory = currentItem;
                dpDrArgs.Name      = new Name(PathTree[pC]);

                ItemOperationStatus pDirOpRes =
                    _ProtocolV2.NFSPROC_LOOKUP(dpDrArgs);

                if (pDirOpRes != null &&
                    pDirOpRes.Status == NFSStats.NFS_OK)
                {
                    currentItem = pDirOpRes.OK.HandleObject;

                    if (PathTree.Length - 1 == pC)
                    {
                        attributes = new NFSAttributes(
                            pDirOpRes.OK.Attributes.CreateTime.Seconds,
                            pDirOpRes.OK.Attributes.LastAccessedTime.Seconds,
                            pDirOpRes.OK.Attributes.ModifiedTime.Seconds,
                            pDirOpRes.OK.Attributes.Type,
                            pDirOpRes.OK.Attributes.Mode,
                            pDirOpRes.OK.Attributes.Size,
                            pDirOpRes.OK.HandleObject.Value);
                    }
                }
                else
                {
                    if (pDirOpRes == null || pDirOpRes.Status == NFSStats.NFSERR_NOENT)
                    {
                        attributes = null;
                        break;
                    }

                    if (ThrowExceptionIfNotFound)
                    {
                        ExceptionHelpers.ThrowException(pDirOpRes.Status);
                    }
                }
            }

            return(attributes);
        }