32
32
import java .util .HashSet ;
33
33
import java .util .Set ;
34
34
35
+ import org .mycore .common .config .MCRConfiguration2 ;
35
36
import org .mycore .common .digest .MCRDigest ;
36
37
import org .mycore .common .events .MCREvent ;
37
38
import org .mycore .datamodel .niofs .MCRVersionedPath ;
38
39
import org .mycore .ocfl .niofs .storage .MCROCFLTempFileStorage ;
39
40
import org .mycore .ocfl .repository .MCROCFLRepository ;
40
41
42
+ import io .ocfl .api .model .FileChangeHistory ;
41
43
import io .ocfl .api .model .ObjectVersionId ;
42
44
import io .ocfl .api .model .OcflObjectVersion ;
43
45
44
46
/**
45
- * Represents a virtual object stored locally in an OCFL repository.
47
+ * Represents a virtual object that is stored on the same drive as the OCFL repository. This provides the implementation
48
+ * direct access to the files of the OCFL repository when needed. For example a file can be accessed directly for read
49
+ * operations without copying it first to the local storage.
46
50
* <p>
47
51
* This class extends {@link MCROCFLVirtualObject} and provides implementations specific to local storage.
48
52
* It handles file operations such as copying, moving, and deleting files within the local file system,
@@ -90,7 +94,8 @@ public MCROCFLLocalVirtualObject(MCROCFLRepository repository, OcflObjectVersion
90
94
* @param directoryTracker the directory tracker.
91
95
*/
92
96
protected MCROCFLLocalVirtualObject (MCROCFLRepository repository , ObjectVersionId versionId ,
93
- OcflObjectVersion objectVersion , MCROCFLTempFileStorage localStorage , boolean readonly ,
97
+ OcflObjectVersion objectVersion , MCROCFLTempFileStorage localStorage ,
98
+ boolean readonly ,
94
99
MCROCFLFileTracker <MCRVersionedPath , MCRDigest > fileTracker ,
95
100
MCROCFLEmptyDirectoryTracker directoryTracker ) {
96
101
super (repository , versionId , objectVersion , localStorage , readonly , fileTracker , directoryTracker );
@@ -100,7 +105,7 @@ protected MCROCFLLocalVirtualObject(MCROCFLRepository repository, ObjectVersionI
100
105
* {@inheritDoc}
101
106
*/
102
107
@ Override
103
- public void copyFile (MCRVersionedPath source , MCRVersionedPath target , CopyOption ... options ) throws IOException {
108
+ public void copy (MCRVersionedPath source , MCRVersionedPath target , CopyOption ... options ) throws IOException {
104
109
checkPurged (source );
105
110
checkReadOnly ();
106
111
boolean targetExists = exists (target );
@@ -119,7 +124,7 @@ public void copyFile(MCRVersionedPath source, MCRVersionedPath target, CopyOptio
119
124
* {@inheritDoc}
120
125
*/
121
126
@ Override
122
- public void copyFileToVirtualObject (MCROCFLVirtualObject virtualTarget , MCRVersionedPath source ,
127
+ public void externalCopy (MCROCFLVirtualObject virtualTarget , MCRVersionedPath source ,
123
128
MCRVersionedPath target , CopyOption ... options ) throws IOException {
124
129
checkPurged (source );
125
130
virtualTarget .checkReadOnly ();
@@ -172,39 +177,40 @@ protected SeekableByteChannel readOrWriteByteChannel(MCRVersionedPath path, Set<
172
177
173
178
@ Override
174
179
public FileTime getModifiedTime (MCRVersionedPath path ) throws IOException {
175
- checkPurged (path );
176
180
checkExists (path );
177
181
Path physicalPath = toPhysicalPath (path );
178
182
return Files .readAttributes (physicalPath , BasicFileAttributes .class ).lastModifiedTime ();
179
183
}
180
184
181
185
@ Override
182
186
public FileTime getAccessTime (MCRVersionedPath path ) throws IOException {
183
- checkPurged (path );
184
187
checkExists (path );
185
188
Path physicalPath = toPhysicalPath (path );
186
189
return Files .readAttributes (physicalPath , BasicFileAttributes .class ).lastAccessTime ();
187
190
}
188
191
189
- @ Override
190
- public long getSize (MCRVersionedPath path ) throws IOException {
191
- checkPurged (path );
192
+ /**
193
+ * {@inheritDoc}
194
+ */
195
+ public Path toPhysicalPath (MCRVersionedPath path ) throws IOException {
192
196
checkExists (path );
193
- if (isDirectory (path )) {
194
- return 0 ;
197
+ if (this . localStorage . exists (path )) {
198
+ return this . localStorage . toPhysicalPath ( path ) ;
195
199
}
196
- Path physicalPath = toPhysicalPath (path );
197
- return Files .size (physicalPath );
200
+ FileChangeHistory changeHistory = getChangeHistory (path );
201
+ String storageRelativePath = changeHistory .getMostRecent ().getStorageRelativePath ();
202
+ return getLocalRepositoryPath ().resolve (storageRelativePath );
198
203
}
199
204
200
- @ Override
201
- public Object getFileKey (MCRVersionedPath path ) throws IOException {
202
- checkPurged (path );
203
- checkExists (path );
204
- // TODO the fileKey between the localstorage and the ocfl repository should always be the same
205
- // this implementation is just a hack for testing
206
- Path physicalPath = toPhysicalPath (path );
207
- return Files .readAttributes (physicalPath , BasicFileAttributes .class ).fileKey ();
205
+ /**
206
+ * Returns the local OCFL repository path.
207
+ *
208
+ * @return the local repository path.
209
+ */
210
+ protected Path getLocalRepositoryPath () {
211
+ return Path .of (MCRConfiguration2
212
+ .getString ("MCR.OCFL.Repository." + repository .getId () + ".RepositoryRoot" )
213
+ .orElseThrow ());
208
214
}
209
215
210
216
/**
0 commit comments