コード例 #1
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		static public void AddRoot (FileModel root)
		{
			if (! root.IsRoot)
				throw new Exception ("Attempted to add non-root as root");

			roots.Add (root);
		}
コード例 #2
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		//////////////////////////////////////////////////////////////

		// Useful utility functions

		static private string PickName (FileModel p)
		{
			string pick;
			do {
				pick = Token.GetRandom ();
			} while (p.children.Contains (pick));
			return pick;
		}
コード例 #3
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		// If the move would cause a filename collision or is
		// otherwise impossible, return false.  Return true if the
		// move actually happens.
		public bool MoveTo (FileModel new_parent, // or null, to just rename
				    string    new_name)   // or null, to just move
		{
			if (! new_parent.IsDirectory)
				throw new ArgumentException ("Parent must be a directory");

			if (this.IsRoot)
				throw new ArgumentException ("Can't move a root");

			// Impossible
			if (this == new_parent || this.IsAbove (new_parent))
				return false;

			string old_path;
			old_path = this.FullName;

			if (new_parent == null)
				new_parent = this.parent;
			if (new_name == null)
				new_name = this.name;

			// check for a filename collision
			if (new_parent.children.Contains (new_name))
				return false;

			// modify the data structure
			this.parent.children.Remove (this.name);
			this.parent = new_parent;
			this.name = new_name;
			this.parent.children [this.name] = this;
			
			string new_path;
			new_path = Path.Combine (new_parent.FullName, new_name);

			if (this.IsDirectory)
				Directory.Move (old_path, new_path);
			else
				File.Move (old_path, new_path);

			return true;
		}
コード例 #4
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		public void Delete ()
		{
			if (IsRoot)
				throw new Exception ("Can't delete the root!");

			if (IsDirectory)
				Directory.Delete (FullName, true); // recursive
			else
				File.Delete (FullName);

			parent.children.Remove (name);
			parent = null;
		}
コード例 #5
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		public FileModel NewFile ()
		{
			if (! IsDirectory)
				throw new ArgumentException ("parent must be a directory");

			// no more names left
			if (children.Count == Token.Count)
				return null;

			FileModel child;
			child = new FileModel ();
			child.name = PickName (this);
			child.body = NewBody (10);

			child.parent = this;
			children [child.name] = child;

			// Create the file
			child.Write ();

			return child;
		}
コード例 #6
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		// Creates a randomly-named new directory.
		// Avoid name collisions with existing files.
		public FileModel NewDirectory ()
		{
			if (! IsDirectory)
				throw new ArgumentException ("parent must be a directory");

			// no more names left
			if (children.Count == Token.Count)
				return null;

			FileModel child;
			child = new FileModel ();
			child.name = PickName (this);
			child.children = new Hashtable ();

			child.parent = this;
			children [child.name] = child;

			// Actually create the directory
			Directory.CreateDirectory (child.FullName);
			child.mtime = Directory.GetLastWriteTimeUtc (child.FullName);

			return child;
		}
コード例 #7
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		public static FileModel NewRoot ()
		{
			FileModel root = new FileModel ();
			root.name = PathFinder.HomeDir;
			root.children = new Hashtable ();
			root.mtime = Directory.GetLastWriteTimeUtc (root.FullName);
			return root;
		}
コード例 #8
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		// IsBelow is easier to thik about than IsDescendantOf
		public bool IsBelow (FileModel other)
		{
			return other.IsAbove (this);
		}
コード例 #9
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
		// IsAbove is easier to think about than IsAncestorOf
		public bool IsAbove (FileModel other)
		{
			return this == other.parent 
				|| (other.parent != null && IsAbove (other.parent));
		}
コード例 #10
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
 // IsBelow is easier to thik about than IsDescendantOf
 public bool IsBelow(FileModel other)
 {
     return(other.IsAbove(this));
 }
コード例 #11
0
ファイル: FileModel.cs プロジェクト: ArsenShnurkov/beagle-1
 // IsAbove is easier to think about than IsAncestorOf
 public bool IsAbove(FileModel other)
 {
     return(this == other.parent ||
            (other.parent != null && IsAbove(other.parent)));
 }