Exemplo n.º 1
0
        public override Int32 Rename(
            Object FileNode0,
            Object FileDesc,
            String FileName,
            String NewFileName,
            Boolean ReplaceIfExists)
        {
            FileNode FileNode = (FileNode)FileNode0;
            FileNode NewFileNode;

            NewFileNode = FileNodeMap.Get(NewFileName);
            if (null != NewFileNode && FileNode != NewFileNode)
            {
                if (!ReplaceIfExists)
                {
                    return(STATUS_OBJECT_NAME_COLLISION);
                }
                if (0 != (NewFileNode.FileInfo.FileAttributes & (UInt32)FileAttributes.Directory))
                {
                    return(STATUS_ACCESS_DENIED);
                }
            }

            if (null != NewFileNode && FileNode != NewFileNode)
            {
                FileNodeMap.Remove(NewFileNode);
            }

            List <String> DescendantFileNames = new List <String>(FileNodeMap.GetDescendantFileNames(FileNode));

            foreach (String DescendantFileName in DescendantFileNames)
            {
                FileNode DescendantFileNode = FileNodeMap.Get(DescendantFileName);
                if (null == DescendantFileNode)
                {
                    continue; /* should not happen */
                }
                FileNodeMap.Remove(DescendantFileNode);
                DescendantFileNode.FileName =
                    NewFileName + DescendantFileNode.FileName.Substring(FileName.Length);
                FileNodeMap.Insert(DescendantFileNode);
            }

            return(STATUS_SUCCESS);
        }