@@ -78,34 +78,34 @@ public Boolean IsCancel
7878
7979 public void Execute ( )
8080 {
81- try
82- {
83- if ( this . IsAbort ) { return ; }
81+ if ( this . IsAbort ) { return ; }
8482
85- // Check file name equality.
86- if ( ! this . CheckDiffer ( this . Entry . Source , this . Entry . Target ) )
87- {
88- return ;
89- }
83+ // Check file name equality.
84+ if ( ! this . CheckDiffer ( this . Entry . Source , this . Entry . Target ) )
85+ {
86+ return ;
87+ }
9088
91- if ( this . IsAbort ) { return ; }
89+ if ( this . IsAbort ) { return ; }
9290
93- // Check and validate source file.
94- if ( ! this . CheckSource ( this . Entry . Source ) )
95- {
96- return ;
97- }
91+ // Check and validate source file.
92+ if ( ! this . CheckSource ( this . Entry . Source ) )
93+ {
94+ return ;
95+ }
9896
99- if ( this . IsAbort ) { return ; }
97+ if ( this . IsAbort ) { return ; }
10098
101- // Check and validate target file.
102- if ( ! this . CheckTarget ( this . Entry . Target ) )
103- {
104- return ;
105- }
99+ // Check and validate target file.
100+ if ( ! this . CheckTarget ( this . Entry . Target , this . Entry . IsOverwrite ) )
101+ {
102+ return ;
103+ }
106104
107- if ( this . IsAbort ) { return ; }
105+ if ( this . IsAbort ) { return ; }
108106
107+ try
108+ {
109109 using ( new PlaylistEntryExecutionTimer ( this . logger , this . GetExecutionDetails ( ) ) )
110110 using ( IncrementalHash sourceHash = IncrementalHash . CreateHash ( HashAlgorithmName . MD5 ) )
111111 using ( IncrementalHash targetHash = IncrementalHash . CreateHash ( HashAlgorithmName . MD5 ) )
@@ -146,6 +146,10 @@ public void Execute()
146146 // case of an unsuccessful termination (!error && !cancel).
147147 this . DeleteSource ( this . Entry . Source ) ;
148148
149+ // Remove origin file in case of moving is enabled but not in
150+ // case of an unsuccessful termination (!error && !cancel).
151+ this . DeleteSource ( this . Entry . Origin ) ;
152+
149153 // Remove target file but only in case of an unsuccessful
150154 // termination (error || cancel).
151155 this . DeleteTarget ( this . Entry . Target ) ;
@@ -156,7 +160,7 @@ public void Execute()
156160
157161 #region Private properties
158162
159- public Boolean IsAbort
163+ private Boolean IsAbort
160164 {
161165 get
162166 {
@@ -278,14 +282,18 @@ private Boolean CheckSource(String sourceFile)
278282 /// <summary>
279283 /// Validates the target file (not empty) and creates the folder structure
280284 /// if necessary. Additionally, all existing file attributes are released.
285+ /// But only if target file already exists and overwrite mode is enabled.
281286 /// </summary>
282287 /// <param name="targetFile">
283288 /// The target file to check.
284289 /// </param>
290+ /// <param name="overwrite">
291+ /// Current overwrite mode.
292+ /// </param>
285293 /// <returns>
286294 /// True, if successful and false otherwise.
287295 /// </returns>
288- private Boolean CheckTarget ( String targetFile )
296+ private Boolean CheckTarget ( String targetFile , Boolean overwrite )
289297 {
290298 if ( String . IsNullOrWhiteSpace ( targetFile ) )
291299 {
@@ -309,6 +317,17 @@ private Boolean CheckTarget(String targetFile)
309317
310318 if ( nominee . Exists )
311319 {
320+ if ( ! overwrite )
321+ {
322+ // Do not set error flag!
323+ this . logger . Warning (
324+ MethodBase . GetCurrentMethod ( ) ,
325+ "Target file exists and overwrite is disabled." ,
326+ this . GetTargetFileDetail ( targetFile ) ) ;
327+
328+ return false ;
329+ }
330+
312331 nominee . Attributes = FileAttributes . Normal ; // Release all attributes.
313332 }
314333
@@ -461,6 +480,8 @@ private void DeleteSource(String source)
461480 {
462481 try
463482 {
483+ if ( String . IsNullOrWhiteSpace ( source ) ) { return ; }
484+
464485 // Don't do anything in case of abort state.
465486 if ( this . IsAbort ) { return ; }
466487
@@ -497,6 +518,8 @@ private void DeleteTarget(String target)
497518 {
498519 try
499520 {
521+ if ( String . IsNullOrWhiteSpace ( target ) ) { return ; }
522+
500523 // Don't do anything in case of success state.
501524 if ( ! this . IsAbort ) { return ; }
502525
0 commit comments