7 [Hammer (Name
="Basic:CreateFile")]
8 public class Basic_CreateFile
: IHammer
{
10 public bool HammerOnce (DirectoryObject dir
, EventTracker tracker
)
13 created
= new TextFileObject (); // FIXME: or an archive
15 DirectoryObject parent
;
16 parent
= dir
.PickDirectory ();
17 parent
.AddChild (created
, tracker
);
19 Log
.Info ("Created file '{0}'", created
.ShortName
);
25 [Hammer (Name
="Basic:ClobberFile")]
26 public class Basic_ClobberFile
: IHammer
{
28 public bool HammerOnce (DirectoryObject dir
, EventTracker tracker
)
33 victim
= dir
.PickChildFile ();
34 } while (victim
!= null && victim
.IsWritable
);
39 // Create an object w/ the right type
41 created
= TreeBuilder
.NewFile (5, 10, victim
.Extension
, 0.1, 0.5, null); // FIXME: stupid magic numbers
43 Log
.Info ("Clobbered file '{0}'", victim
.ShortName
);
44 victim
.Parent
.ClobberingAddChild (created
, victim
, tracker
);
50 [Hammer (Name
="Basic:CreateDirectory")]
51 public class Basic_CreateDirectory
: IHammer
{
53 public bool HammerOnce (DirectoryObject dir
, EventTracker tracker
)
55 DirectoryObject created
;
56 created
= new DirectoryObject ();
58 DirectoryObject parent
;
59 parent
= dir
.PickDirectory ();
60 parent
.AddChild (created
, tracker
);
62 Log
.Info ("Created directory {0}", created
.ShortName
);
68 ///////////////////////////////////////////////////////////////////////////////
70 [Hammer (Name
="Basic:DeleteFile")]
71 public class Basic_DeleteFile
: IHammer
{
73 public bool HammerOnce (DirectoryObject dir
, EventTracker tracker
)
76 target
= dir
.PickChildFile ();
80 Log
.Info ("Deleted file '{0}'", target
.ShortName
);
81 target
.Parent
.RemoveChild (target
, tracker
);
87 [Hammer (Name
="Basic:DeleteDirectory")]
88 public class Basic_DeleteDirectory
: IHammer
{
90 public bool HammerOnce (DirectoryObject dir
, EventTracker tracker
)
92 DirectoryObject target
;
93 target
= dir
.PickChildDirectory ();
97 Log
.Info ("Deleted directory '{0}'", target
.ShortName
);
98 target
.Parent
.RemoveChild (target
, tracker
);
104 ///////////////////////////////////////////////////////////////////////////////
106 public abstract class Basic_Move
: IHammer
{
108 abstract protected FileSystemObject
PickTarget (DirectoryObject dir
);
110 public bool HammerOnce (DirectoryObject dir
, EventTracker tracker
)
112 DirectoryObject new_parent
;
113 new_parent
= dir
.PickDirectory ();
115 // 10 is a stupid magic number here.
116 FileSystemObject target
= null;
117 for (int i
= 0; i
< 10 && target
== null; ++i
) {
118 target
= PickTarget (dir
);
121 if (target
.IsAncestorOf (new_parent
))
127 Log
.Spew ("Moved {0} to {1}", target
.ShortName
, new_parent
.ShortName
);
128 target
.Parent
.MoveChild (target
, new_parent
, tracker
);
133 [Hammer (Name
="Basic:MoveFile")]
134 public class Basic_MoveFile
: Basic_Move
{
136 override protected FileSystemObject
PickTarget (DirectoryObject dir
)
138 return dir
.PickChildFile ();
142 [Hammer (Name
="Basic:MoveDirectory")]
143 public class Basic_MoveDirectory
: Basic_Move
{
145 override protected FileSystemObject
PickTarget (DirectoryObject dir
)
147 return dir
.PickChildDirectory ();