This project has retired. For details please refer to its
Attic page.
CopyFileEvent xref
1 package org.apache.archiva.transaction;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.List;
25
26 import org.apache.commons.io.FileUtils;
27 import org.codehaus.plexus.digest.Digester;
28
29
30
31
32
33
34 public class CopyFileEvent
35 extends AbstractTransactionEvent
36 {
37 private final File source;
38
39 private final File destination;
40
41
42
43
44
45
46
47 public CopyFileEvent( File source, File destination, List<? extends Digester> digesters )
48 {
49 super( digesters );
50 this.source = source;
51 this.destination = destination;
52 }
53
54 @Override
55 public void commit()
56 throws IOException
57 {
58 createBackup( destination );
59
60 mkDirs( destination.getParentFile() );
61
62 FileUtils.copyFile( source, destination );
63
64 createChecksums( destination, true );
65 copyChecksums();
66
67 copyChecksum( "asc" );
68 }
69
70
71
72
73
74
75 private void copyChecksums()
76 throws IOException
77 {
78 for ( Digester digester : getDigesters() )
79 {
80 copyChecksum( getDigesterFileExtension( digester ) );
81 }
82 }
83
84
85
86
87
88
89
90
91 private boolean copyChecksum( String extension )
92 throws IOException
93 {
94 File checksumSource = new File( source.getAbsolutePath() + "." + extension );
95 if ( checksumSource.exists() )
96 {
97 File checksumDestination = new File( destination.getAbsolutePath() + "." + extension );
98 FileUtils.copyFile( checksumSource, checksumDestination );
99 return true;
100 }
101 return false;
102 }
103
104 @Override
105 public void rollback()
106 throws IOException
107 {
108 destination.delete();
109
110 revertFilesCreated();
111
112 revertMkDirs();
113
114 restoreBackups();
115 }
116 }