Пример #1
0
        public bool HammerOnce(DirectoryObject dir, EventTracker tracker)
        {
            DirectoryObject new_parent;

            new_parent = dir.PickDirectory();

            // 10 is a stupid magic number here.
            FileSystemObject target = null;

            for (int i = 0; i < 10 && target == null; ++i)
            {
                target = PickTarget(dir);
                if (target == null)
                {
                    return(false);
                }
                if (target.IsAncestorOf(new_parent))
                {
                    target = null;
                }
            }
            if (target == null)
            {
                return(false);
            }

            Log.Spew("Moved {0} to {1}", target.ShortName, new_parent.ShortName);
            target.Parent.MoveChild(target, new_parent, tracker);
            return(true);
        }
Пример #2
0
        public virtual void MoveChild(FileSystemObject child, FileSystemObject new_parent, EventTracker tracker)
        {
            if (child.parent != this)
            {
                throw new Exception(child.Uri.ToString() + " is not a child of " + Uri.ToString());
            }

            if (new_parent == null || new_parent == child.parent)
            {
                return;
            }

            // We can't move child into new_parent if child is
            // already above new_parent in the tree.
            if (child.IsAncestorOf(new_parent))
            {
                throw new Exception("Can't move " + child.Uri.ToString() + " to " + new_parent.Uri.ToString());
            }

            string old_full_name;

            old_full_name = child.FullName;

            // FIXME: We need to handle the case of the moved
            // child clobbering another w/ the same name.

            child.parent = new_parent;
            this.children.Remove(child.Name);
            new_parent.children [child.Name] = child;

            // FIXME: What if this is not rooted, but new_parent is?
            if (new_parent.IsRooted)
            {
                child.MoveOnDisk(old_full_name, tracker);
            }
        }
Пример #3
0
		public virtual void MoveChild (FileSystemObject child, FileSystemObject new_parent, EventTracker tracker)
		{
			if (child.parent != this)
				throw new Exception (child.Uri.ToString () + " is not a child of " + Uri.ToString ());

			if (new_parent == null || new_parent == child.parent)
				return;

			// We can't move child into new_parent if child is
			// already above new_parent in the tree.
			if (child.IsAncestorOf (new_parent))
				throw new Exception ("Can't move " + child.Uri.ToString () + " to " + new_parent.Uri.ToString ());
			
			string old_full_name;
			old_full_name = child.FullName;

			// FIXME: We need to handle the case of the moved
			// child clobbering another w/ the same name.

			child.parent = new_parent;
			this.children.Remove (child.Name);
			new_parent.children [child.Name] = child;

			// FIXME: What if this is not rooted, but new_parent is?
			if (new_parent.IsRooted)
				child.MoveOnDisk (old_full_name, tracker);
		}