Пример #1
0
        /// <summary>
        /// Helper method for Sync().
        /// </summary>
        private void SyncRecursive(KfsLocalDirectory dir, KfsScanObject obj)
        {
            // We're synchronizing a directory.
            if (obj is KfsScanDirectory)
            {
                KfsScanDirectory objAsDir = (KfsScanDirectory)obj;
                KfsLocalDirectory subDir = null;

                // We're synchronizing the root directory.
                if (dir == null)
                {
                    subDir = m_share.LocalView.Root;
                }

                else
                {
                    // Make sure the subdirectory exists.
                    if (!dir.ContainsDirectory(obj.Name))
                    {
                        if (dir.Contains(obj.Name))
                            dir.GetObject(obj.Name).RemoveFromView();

                        new KfsLocalDirectory(m_share, dir, obj.Name);
                    }

                    subDir = dir.GetDirectory(obj.Name);
                }

                // Remove the stale children.
                SortedDictionary<String, KfsLocalObject> subDirChildTree =
                    new SortedDictionary<String, KfsLocalObject>(subDir.ChildTree);
                foreach (KfsLocalObject o in subDirChildTree.Values)
                {
                    if (!objAsDir.Contains(o.Name))
                    {
                        o.RemoveFromView();
                    }
                }

                // Synchronize the children.
                foreach (KfsScanObject o in objAsDir.ChildTree.Values)
                {
                    SyncRecursive(subDir, o);
                }
            }

            // We're synchronizing a file.
            else
            {
                if (!dir.ContainsFile(obj.Name))
                {
                    if (dir.Contains(obj.Name))
                        dir.GetObject(obj.Name).RemoveFromView();

                    new KfsLocalFile(m_share, dir, obj.Name);
                }

                // Request the local status of the file to be updated.
                KfsServerFile serverFile = dir.GetFile(obj.Name).GetServerCounterpart();
                if (serverFile != null) serverFile.RequestUpdate();
            }
        }
Пример #2
0
 public void Add(KfsScanObject _object)
 {
     Debug.Assert(!Contains(_object.Name));
     ChildTree.Add(_object.Name, _object);
 }
Пример #3
0
        /// <summary>
        /// Scan the content of SubtreePath. IMPORTANT: if SubtreePath does not
        /// exist on disk, then this method must update SubtreePath to the first 
        /// subtree that actually exist.
        /// </summary>
        public void Scan()
        {
            String fullPath = m_share.MakeAbsolute(m_subtreePath);
            Logging.Log("KfsScan() called (" + m_subtreePath + ")");

            // The target path is a file.
            if (File.Exists(fullPath) && KfsPath.BaseName(fullPath) != KfsShare.FsMarker)
            {
                Logging.Log("Found an existing file on disk.");
                m_subtreeObject = new KfsScanFile(KfsPath.BaseName(m_subtreePath));
                return;
            }

            // The target path is a directory. Scan it recursively.
            if (Directory.Exists(fullPath))
            {
                Logging.Log("Found a directory on disk");
                m_subtreeObject = new KfsScanDirectory(KfsPath.BaseName(m_subtreePath));
                ScanRecursive(m_subtreeObject as KfsScanDirectory, m_subtreePath);
                return;
            }

            // The target path does not exist. Find the first object that does exist.
            // This is tricky...
            while (true)
            {
                // Get the parent, if there is one. The parent of the root is
                // the root itself in this context.
                String parentRelPath = KfsPath.StripTrailingDelim(KfsPath.DirName(m_subtreePath));
                String parentFullPath = m_share.MakeAbsolute(parentRelPath);

                // Update the target path to match the file, unless the parent path is
                // the root itself (the root must not be a file).
                if (parentRelPath != "" && File.Exists(parentFullPath))
                {
                    m_subtreePath = parentRelPath;
                    m_subtreeObject = new KfsScanFile(KfsPath.BaseName(m_subtreePath));
                    return;
                }

                // Remember that the target path does not exist, unless the target path
                // is the root itself (someone might have deleted then created the root
                // quickly, there is a race condition here).
                if (m_subtreePath != "" && Directory.Exists(parentFullPath))
                {
                    m_subtreeObject = null;
                    return;
                }

                // This can occur if the root directory does not exist. Create it
                // again in this case.
                if (parentRelPath == "")
                {
                    if (!Directory.Exists(parentFullPath)) Directory.CreateDirectory(parentFullPath);
                    m_subtreePath = "";
                    m_subtreeObject = new KfsScanDirectory("");
                    return;
                }

                // Consider the parent directory.
                m_subtreePath = parentRelPath;
            }
        }