예제 #1
0
        int DokanOperations.OpenDirectory(string filename, DokanFileInfo info)
        {
            mLog.DebugFormat("OpenDirectory - [{0}]", filename);

            if (mHistoryDirectories.CreateNewDir(filename, FileAccess.Read, GetRoot(), mPlasticApi))
            {
                DirectoryContext.Set(info);
                return(0);
            }

            DirectoryContext.Set(info);

            Node node = WalkTree.Find(GetRoot(), filename);

            return(node != null ? 0 : -DokanNet.ERROR_PATH_NOT_FOUND);
        }
예제 #2
0
        int DokanOperations.CreateFile(
            string path,
            FileAccess access,
            FileShare share,
            FileMode mode,
            FileOptions options,
            DokanFileInfo info)
        {
            mLog.DebugFormat(
                "CreateFile - mode: {0, 5} - options: {1, 5} - {2}",
                mode, options, path);

            Node tree = GetRoot();

            Node node = WalkTree.Find(tree, path);

            if (node == null)
            {
                int  error;
                bool bIsDirectory;

                int handle = CreateNew.Create(
                    path,
                    access,
                    share,
                    mode,
                    options,
                    tree,
                    mFileCache,
                    mHandles,
                    mPlasticApi,
                    mLocalFiles,
                    mHistoryDirectories,
                    out bIsDirectory,
                    out error);

                if (error != 0)
                {
                    return(error);
                }

                if (bIsDirectory)
                {
                    DirectoryContext.Set(info);
                }
                else
                {
                    FileContext.Set(info, handle);
                }

                return(0);
            }

            if (mHistoryDirectories.OpenExisting(node))
            {
                DirectoryContext.Set(info);
                return(0);
            }

            if (node.IsDirectory())
            {
                DirectoryContext.Set(info);
                return(0);
            }

            IVirtualFile virtualFile;

            if ((virtualFile = mVirtualFiles.Get(node.GetNodeId())) != null)
            {
                int handle = virtualFile.CreateFile(access, share, mode, options);

                FileContext.Set(info, handle);

                return(0);
            }

#warning here me must handle CreateNew which I think should delete the existing file or fail

            if (node.IsControlledAndReadOnly())
            {
                string fileToOpen = mFileCache.GetFile(
                    node.GetRepSpec(),
                    node.CloneRevisionInfo(),
                    path,
                    mPlasticApi);

                if (OpenForRead(access))
                {
                    int handle = mHandles.OpenFile(
                        fileToOpen,
                        path,
                        access, share, mode, options);

                    if (handle == -1)
                    {
                        return(-1);
                    }

                    FileContext.Set(info, handle);

                    return(0);
                }

                // then we need to check it out and copy the content
                // of the file to the writable storage

                mLog.DebugFormat("**Doing CHECKOUT**");

                string writablePath = mLocalFiles.GetPathForFile(node.GetNodeId());

                File.Copy(fileToOpen, writablePath);

                Checkout(node, path, mChangesTreeOperations);
            }

            // return the existing private file
            int fhandle = LocalFile.OpenExisting(
                node.GetNodeId(),
                path,
                access,
                share,
                mode,
                options,
                mLocalFiles);

            if (fhandle == -1)
            {
                return(-DokanNet.ERROR_FILE_NOT_FOUND);
            }

            FileContext.Set(info, fhandle);

            return(fhandle);
        }