Esempio n. 1
0
 public Nfs3Procedure.Status TryGetSharedObject(String localPathAndName, String shareName, out ShareObject shareObject)
 {
     if (shareObjectsByLocalPath.TryGetValue(localPathAndName, out shareObject))
     {
         Nfs3Procedure.Status status = shareObject.CheckStatus();
         if (status != Nfs3Procedure.Status.Ok)
         {
             DisposeShareObject(shareObject);
         }
         return(status);
     }
     else
     {
         if (File.Exists(localPathAndName))
         {
             shareObject = CreateNewShareObject(FileType.Regular, localPathAndName, shareName);
             return(Nfs3Procedure.Status.Ok);
         }
         else if (Directory.Exists(localPathAndName))
         {
             shareObject = CreateNewShareObject(FileType.Directory, localPathAndName, shareName);
             return(Nfs3Procedure.Status.Ok);
         }
         else
         {
             return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
         }
     }
 }
Esempio n. 2
0
        public Nfs3Procedure.Status TryGetSharedObject(Byte[] handle, out ShareObject shareObject)
        {
            if (!shareObjectsByHandle.TryGetValue(handle, out shareObject))
            {
                if (NfsServerLog.sharedFileSystemLogger != null)
                {
                    NfsServerLog.sharedFileSystemLogger.WriteLine("[SharedFileSystem] [Warning] File handle not found in dictionary: {0}", BitConverter.ToString(handle));
                }
                return(Nfs3Procedure.Status.ErrorBadHandle);
            }

            Nfs3Procedure.Status status = shareObject.CheckStatus();
            if (status != Nfs3Procedure.Status.Ok)
            {
                DisposeShareObject(shareObject);
            }
            return(status);
        }
Esempio n. 3
0
        public Nfs3Procedure.Status Move(ShareObject oldParentShareObject, String oldName,
                                         ShareObject newParentShareObject, String newName)
        {
            Nfs3Procedure.Status status;

            status = newParentShareObject.CheckStatus();
            if (status != Nfs3Procedure.Status.Ok)
            {
                DisposeShareObject(newParentShareObject);
                return(status);
            }

            status = oldParentShareObject.CheckStatus();
            if (status != Nfs3Procedure.Status.Ok)
            {
                DisposeShareObject(oldParentShareObject);
                return(status);
            }

            //
            // Get Old Share Object
            //
            String oldLocalPathAndName = PlatformPath.LocalCombine(oldParentShareObject.localPathAndName, oldName);

            ShareObject oldShareObject;

            if (!shareObjectsByLocalPath.TryGetValue(oldLocalPathAndName, out oldShareObject))
            {
                return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
            }

            status = oldShareObject.CheckStatus();
            if (status != Nfs3Procedure.Status.Ok)
            {
                DisposeShareObject(oldShareObject);
                return(status);
            }

            //
            // Move
            //
            String   newLocalPathAndName = PlatformPath.LocalCombine(newParentShareObject.localPathAndName, newName);
            FileType fileType            = oldShareObject.fileType;

            if (Directory.Exists(newLocalPathAndName))
            {
                if (oldShareObject.fileType != FileType.Directory)
                {
                    return(Nfs3Procedure.Status.ErrorAlreadyExists);
                }

                try
                {
                    Directory.Delete(newLocalPathAndName);
                }
                catch (IOException)
                {
                    return(Nfs3Procedure.Status.ErrorDirectoryNotEmpty); // The directory is not empty
                }

                Directory.Move(oldLocalPathAndName, newLocalPathAndName);
            }
            else if (File.Exists(newLocalPathAndName))
            {
                if (oldShareObject.fileType != FileType.Regular)
                {
                    return(Nfs3Procedure.Status.ErrorAlreadyExists);
                }

                File.Delete(newLocalPathAndName);

                File.Move(oldLocalPathAndName, newLocalPathAndName);
            }
            else
            {
                if (oldShareObject.fileType == FileType.Regular)
                {
                    File.Move(oldLocalPathAndName, newLocalPathAndName);
                }
                else if (oldShareObject.fileType == FileType.Directory)
                {
                    Directory.Move(oldLocalPathAndName, newLocalPathAndName);
                }
                else
                {
                    return(Nfs3Procedure.Status.ErrorInvalidArgument);
                }
            }

            //
            // Update the share object and return
            //
            UpdateShareObjectPathAndName(oldShareObject, newLocalPathAndName, newName);
            oldShareObject.RefreshFileAttributes(permissions);
            status = oldShareObject.CheckStatus();
            if (status != Nfs3Procedure.Status.Ok)
            {
                DisposeShareObject(oldShareObject);
            }
            return(status);
        }