Skip to content

Commit 9bd4843

Browse files
committed
iRODS: Clean up business logic code
1 parent 59703e1 commit 9bd4843

17 files changed

+523
-774
lines changed
Lines changed: 49 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package ch.cyberduck.core.irods;
22

3-
import java.io.IOException;
4-
import java.util.List;
3+
import ch.cyberduck.core.ListProgressListener;
4+
import ch.cyberduck.core.Path;
5+
import ch.cyberduck.core.PathAttributes;
6+
import ch.cyberduck.core.exception.BackgroundException;
7+
import ch.cyberduck.core.exception.NotfoundException;
8+
import ch.cyberduck.core.features.AttributesAdapter;
9+
import ch.cyberduck.core.features.AttributesFinder;
10+
import ch.cyberduck.core.io.Checksum;
511

612
import org.apache.commons.io.FilenameUtils;
713
import org.apache.commons.lang3.StringUtils;
@@ -13,29 +19,8 @@
1319
import org.irods.irods4j.low_level.api.GenQuery1Columns;
1420
import org.irods.irods4j.low_level.api.IRODSException;
1521

16-
/*
17-
* Copyright (c) 2002-2016 iterate GmbH. All rights reserved.
18-
* https://cyberduck.io/
19-
*
20-
* This program is free software; you can redistribute it and/or modify
21-
* it under the terms of the GNU General Public License as published by
22-
* the Free Software Foundation; either version 2 of the License, or
23-
* (at your option) any later version.
24-
*
25-
* This program is distributed in the hope that it will be useful,
26-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28-
* GNU General Public License for more details.
29-
*/
30-
31-
import ch.cyberduck.core.ListProgressListener;
32-
import ch.cyberduck.core.Path;
33-
import ch.cyberduck.core.PathAttributes;
34-
import ch.cyberduck.core.exception.BackgroundException;
35-
import ch.cyberduck.core.exception.NotfoundException;
36-
import ch.cyberduck.core.features.AttributesAdapter;
37-
import ch.cyberduck.core.features.AttributesFinder;
38-
import ch.cyberduck.core.io.Checksum;
22+
import java.io.IOException;
23+
import java.util.List;
3924

4025

4126
public class IRODSAttributesFinderFeature implements AttributesFinder, AttributesAdapter<List<String>> {
@@ -49,44 +34,45 @@ public IRODSAttributesFinderFeature(final IRODSSession session) {
4934
@Override
5035
public PathAttributes find(final Path file, final ListProgressListener listener) throws BackgroundException {
5136
try {
52-
final PathAttributes[] attributes = new PathAttributes[1];
37+
final PathAttributes[] attributes = new PathAttributes[1];
5338
final IRODSConnection conn = session.getClient();
5439
if(!IRODSFilesystem.exists(this.session.getClient().getRcComm(), file.getAbsolute())) {
5540
throw new NotfoundException(file.getAbsolute());
5641
}
57-
String logicalPath = file.getAbsolute();
58-
String parentPath = FilenameUtils.getFullPathNoEndSeparator(logicalPath);
59-
String fileName = FilenameUtils.getName(logicalPath);
42+
String logicalPath = file.getAbsolute();
43+
String parentPath = FilenameUtils.getFullPathNoEndSeparator(logicalPath);
44+
String fileName = FilenameUtils.getName(logicalPath);
6045
if(Versioning.compareVersions(conn.getRcComm().relVersion.substring(4), "4.3.4") > 0) {
61-
String query = String.format("select DATA_MODIFY_TIME, DATA_CREATE_TIME, DATA_SIZE, DATA_CHECKSUM, DATA_OWNER_NAME, DATA_OWNER_ZONE where COLL_NAME = '%s' and DATA_NAME = '%s'", parentPath, fileName);
62-
List<List<String>> rows = IRODSQuery.executeGenQuery2(conn.getRcComm(), query);
63-
List<String> row = rows.get(0);
64-
attributes[0]=toAttributes(row);
65-
}else {
66-
GenQuery1QueryArgs input = new GenQuery1QueryArgs();
46+
String query = String.format("select DATA_MODIFY_TIME, DATA_CREATE_TIME, DATA_SIZE, DATA_CHECKSUM, DATA_OWNER_NAME, DATA_OWNER_ZONE where COLL_NAME = '%s' and DATA_NAME = '%s'", parentPath, fileName);
47+
List<List<String>> rows = IRODSQuery.executeGenQuery2(conn.getRcComm(), query);
48+
List<String> row = rows.get(0);
49+
attributes[0] = toAttributes(row);
50+
}
51+
else {
52+
GenQuery1QueryArgs input = new GenQuery1QueryArgs();
6753

68-
// select COLL_NAME, DATA_NAME, DATA_ACCESS_TIME
69-
input.addColumnToSelectClause(GenQuery1Columns.COL_D_MODIFY_TIME);
70-
input.addColumnToSelectClause(GenQuery1Columns.COL_D_CREATE_TIME);
71-
input.addColumnToSelectClause(GenQuery1Columns.COL_DATA_SIZE);
72-
input.addColumnToSelectClause(GenQuery1Columns.COL_D_DATA_CHECKSUM);
73-
input.addColumnToSelectClause(GenQuery1Columns.COL_D_OWNER_NAME);
74-
input.addColumnToSelectClause(GenQuery1Columns.COL_D_OWNER_ZONE);
75-
54+
// select COLL_NAME, DATA_NAME, DATA_ACCESS_TIME
55+
input.addColumnToSelectClause(GenQuery1Columns.COL_D_MODIFY_TIME);
56+
input.addColumnToSelectClause(GenQuery1Columns.COL_D_CREATE_TIME);
57+
input.addColumnToSelectClause(GenQuery1Columns.COL_DATA_SIZE);
58+
input.addColumnToSelectClause(GenQuery1Columns.COL_D_DATA_CHECKSUM);
59+
input.addColumnToSelectClause(GenQuery1Columns.COL_D_OWNER_NAME);
60+
input.addColumnToSelectClause(GenQuery1Columns.COL_D_OWNER_ZONE);
7661

77-
// where COLL_NAME like '/tempZone/home/rods and DATA_NAME = 'atime.txt'
78-
String collNameCondStr = String.format("= '%s'", parentPath);
79-
String dataNameCondStr = String.format("= '%s'", fileName);
80-
input.addConditionToWhereClause(GenQuery1Columns.COL_COLL_NAME, collNameCondStr);
81-
input.addConditionToWhereClause(GenQuery1Columns.COL_DATA_NAME, dataNameCondStr);
8262

83-
StringBuilder output = new StringBuilder();
63+
// where COLL_NAME like '/tempZone/home/rods and DATA_NAME = 'atime.txt'
64+
String collNameCondStr = String.format("= '%s'", parentPath);
65+
String dataNameCondStr = String.format("= '%s'", fileName);
66+
input.addConditionToWhereClause(GenQuery1Columns.COL_COLL_NAME, collNameCondStr);
67+
input.addConditionToWhereClause(GenQuery1Columns.COL_DATA_NAME, dataNameCondStr);
8468

85-
IRODSQuery.executeGenQuery1(conn.getRcComm(), input, row -> {
86-
attributes[0]=toAttributes(row);
87-
return false;
88-
});
89-
}
69+
StringBuilder output = new StringBuilder();
70+
71+
IRODSQuery.executeGenQuery1(conn.getRcComm(), input, row -> {
72+
attributes[0] = toAttributes(row);
73+
return false;
74+
});
75+
}
9076
return attributes[0];
9177
}
9278
catch(IOException | IRODSException e) {
@@ -96,18 +82,18 @@ public PathAttributes find(final Path file, final ListProgressListener listener)
9682

9783
@Override
9884
public PathAttributes toAttributes(final List<String> row) {
99-
final IRODSConnection conn = session.getClient();
85+
final IRODSConnection conn = session.getClient();
10086
final PathAttributes attributes = new PathAttributes();
10187
attributes.setModificationDate(Long.parseLong(row.get(0)) * 1000); // seconds to ms
102-
attributes.setCreationDate(Long.parseLong(row.get(1)) * 1000);
103-
attributes.setSize(Long.parseLong(row.get(2)));
104-
String checksum = row.get(3);
105-
if (!StringUtils.isEmpty(checksum)) {
106-
attributes.setChecksum(Checksum.parse(checksum));
107-
}
88+
attributes.setCreationDate(Long.parseLong(row.get(1)) * 1000);
89+
attributes.setSize(Long.parseLong(row.get(2)));
90+
String checksum = row.get(3);
91+
if(!StringUtils.isEmpty(checksum)) {
92+
attributes.setChecksum(Checksum.parse(checksum));
93+
}
10894

109-
attributes.setOwner(conn.getRcComm().relVersion);
110-
attributes.setGroup(row.get(5));
95+
attributes.setOwner(conn.getRcComm().relVersion);
96+
attributes.setGroup(row.get(5));
11197
return attributes;
11298
}
11399
}
Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,84 @@
11
package ch.cyberduck.core.irods;
22

3-
import java.io.IOException;
4-
import java.io.RandomAccessFile;
5-
63
import org.irods.irods4j.high_level.io.IRODSDataObjectInputStream;
74
import org.irods.irods4j.high_level.io.IRODSDataObjectOutputStream;
85
import org.irods.irods4j.high_level.io.IRODSDataObjectStream.SeekDirection;
96
import org.irods.irods4j.low_level.api.IRODSException;
107

11-
public class IRODSChunkWorker implements Runnable{
12-
private final Object stream;
8+
import java.io.IOException;
9+
import java.io.RandomAccessFile;
10+
11+
public class IRODSChunkWorker implements Runnable {
12+
private final Object stream;
1313
private final RandomAccessFile file;
1414
private final long offset;
1515
private final long chunkSize;
1616
private final byte[] buffer;
17-
public IRODSChunkWorker(Object stream, String localfilePath, long offset, long chunkSize, int bufferSize) throws IOException, IRODSException {
18-
this.stream= stream;
19-
this.file=new RandomAccessFile(localfilePath,"rw");
20-
this.offset=offset;
21-
this.chunkSize=chunkSize;
22-
this.buffer=new byte[bufferSize];
23-
2417

25-
file.seek(offset);
26-
}
27-
@Override
28-
public void run(){
29-
try {
30-
if (stream instanceof IRODSDataObjectInputStream) {
31-
IRODSDataObjectInputStream in = (IRODSDataObjectInputStream) (stream);
32-
in.seek((int) offset, SeekDirection.CURRENT);
33-
long remaining = chunkSize;
34-
while (remaining > 0) {
35-
int readLength = (int) Math.min(buffer.length, remaining);
36-
int read = in.read(buffer, 0, readLength);
37-
file.write(buffer, 0, read);
38-
remaining -= read;
39-
}
40-
41-
}else if (stream instanceof IRODSDataObjectOutputStream) {
42-
IRODSDataObjectOutputStream out = (IRODSDataObjectOutputStream) (stream);
43-
out.seek((int) offset, SeekDirection.CURRENT);
44-
long remaining = chunkSize;
45-
while (remaining > 0) {
18+
public IRODSChunkWorker(Object stream, String localfilePath, long offset, long chunkSize, int bufferSize) throws IOException, IRODSException {
19+
this.stream = stream;
20+
this.file = new RandomAccessFile(localfilePath, "rw");
21+
this.offset = offset;
22+
this.chunkSize = chunkSize;
23+
this.buffer = new byte[bufferSize];
24+
25+
26+
file.seek(offset);
27+
}
28+
29+
@Override
30+
public void run() {
31+
try {
32+
if(stream instanceof IRODSDataObjectInputStream) {
33+
IRODSDataObjectInputStream in = (IRODSDataObjectInputStream) (stream);
34+
in.seek((int) offset, SeekDirection.CURRENT);
35+
long remaining = chunkSize;
36+
while(remaining > 0) {
37+
int readLength = (int) Math.min(buffer.length, remaining);
38+
int read = in.read(buffer, 0, readLength);
39+
file.write(buffer, 0, read);
40+
remaining -= read;
41+
}
42+
43+
}
44+
else if(stream instanceof IRODSDataObjectOutputStream) {
45+
IRODSDataObjectOutputStream out = (IRODSDataObjectOutputStream) (stream);
46+
out.seek((int) offset, SeekDirection.CURRENT);
47+
long remaining = chunkSize;
48+
while(remaining > 0) {
4649
int writeLength = (int) Math.min(buffer.length, remaining);
4750
int read = file.read(buffer, 0, writeLength);
48-
if (read == -1) break;
51+
if(read == -1) {
52+
break;
53+
}
4954
out.write(buffer, 0, read);
5055
remaining -= read;
5156
}
52-
}else {
57+
}
58+
else {
5359
throw new IllegalArgumentException("Unsupported stream type");
5460
}
55-
} catch (IOException | IRODSException e) {
56-
e.printStackTrace();
57-
}
58-
try {
59-
close();
60-
} catch (IOException e) {
61-
e.printStackTrace();
62-
}
63-
}
64-
65-
public void close() throws IOException {
61+
}
62+
catch(IOException | IRODSException e) {
63+
e.printStackTrace();
64+
}
65+
try {
66+
close();
67+
}
68+
catch(IOException e) {
69+
e.printStackTrace();
70+
}
71+
}
72+
73+
public void close() throws IOException {
6674
file.close();
67-
if (stream instanceof IRODSDataObjectInputStream) {
68-
IRODSDataObjectInputStream in = (IRODSDataObjectInputStream) (stream);
75+
if(stream instanceof IRODSDataObjectInputStream) {
76+
IRODSDataObjectInputStream in = (IRODSDataObjectInputStream) (stream);
6977
in.close();
70-
} else if (stream instanceof IRODSDataObjectOutputStream) {
71-
IRODSDataObjectOutputStream out = (IRODSDataObjectOutputStream) (stream);
78+
}
79+
else if(stream instanceof IRODSDataObjectOutputStream) {
80+
IRODSDataObjectOutputStream out = (IRODSDataObjectOutputStream) (stream);
7281
out.close();
7382
}
74-
}
83+
}
7584
}

irods/src/main/java/ch/cyberduck/core/irods/IRODSCopyFeature.java

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package ch.cyberduck.core.irods;
22

3-
import java.io.IOException;
4-
import java.util.EnumSet;
3+
import ch.cyberduck.core.ConnectionCallback;
4+
import ch.cyberduck.core.Path;
5+
import ch.cyberduck.core.exception.BackgroundException;
6+
import ch.cyberduck.core.features.Copy;
7+
import ch.cyberduck.core.io.StreamListener;
58

69
import org.irods.irods4j.high_level.connection.IRODSConnection;
710
import org.irods.irods4j.high_level.vfs.CollectionEntry;
@@ -11,28 +14,8 @@
1114
import org.irods.irods4j.low_level.api.IRODSApi.RcComm;
1215
import org.irods.irods4j.low_level.api.IRODSException;
1316

14-
/*
15-
* Copyright (c) 2002-2015 David Kocher. All rights reserved.
16-
* http://cyberduck.ch/
17-
*
18-
* This program is free software; you can redistribute it and/or modify
19-
* it under the terms of the GNU General Public License as published by
20-
* the Free Software Foundation; either version 2 of the License, or
21-
* (at your option) any later version.
22-
*
23-
* This program is distributed in the hope that it will be useful,
24-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26-
* GNU General Public License for more details.
27-
*
28-
* Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
29-
*/
30-
31-
import ch.cyberduck.core.ConnectionCallback;
32-
import ch.cyberduck.core.Path;
33-
import ch.cyberduck.core.exception.BackgroundException;
34-
import ch.cyberduck.core.features.Copy;
35-
import ch.cyberduck.core.io.StreamListener;
17+
import java.io.IOException;
18+
import java.util.EnumSet;
3619

3720
public class IRODSCopyFeature implements Copy {
3821

@@ -48,46 +31,47 @@ public Path copy(final Path source, final Path target, final ch.cyberduck.core.t
4831
final IRODSConnection conn = session.getClient();
4932
final String from = source.getAbsolute();
5033
final String to = target.getAbsolute();
51-
if (source.isFile()) {
34+
if(source.isFile()) {
5235
IRODSFilesystem.copyDataObject(conn.getRcComm(), from, to);
5336

54-
if (listener != null && status.getLength() > 0) {
37+
if(listener != null && status.getLength() > 0) {
5538
listener.sent(status.getLength());
5639
}
5740
}
5841
if(source.isDirectory()) {
59-
this.copyDirectoryRecursively(conn.getRcComm(), from, to);
42+
this.copyDirectoryRecursively(conn.getRcComm(), from, to);
6043
}
6144
return target;
6245
}
6346
catch(IOException | IRODSException e) {
6447
throw new IRODSExceptionMappingService().map("Cannot copy {0}", e, source);
6548
}
6649
}
67-
50+
6851
public static void copyDirectoryRecursively(RcComm rcComm, String source, String target) throws IOException, IRODSException {
6952
// First, create the root of the target directory
70-
if (!IRODSFilesystem.exists(rcComm, target)) {
53+
if(!IRODSFilesystem.exists(rcComm, target)) {
7154
IRODSFilesystem.createCollection(rcComm, target);
7255
}
7356

7457
// Recursively iterate through the source collection
75-
for (CollectionEntry entry : new IRODSCollectionIterator(rcComm, source)) {
58+
for(CollectionEntry entry : new IRODSCollectionIterator(rcComm, source)) {
7659
String relative = entry.path().substring(source.length()); // relative path from source
7760
String targetPath = target + relative;
7861

7962
ObjectStatus status = entry.status();
8063

81-
if (status.getType() == ObjectStatus.ObjectType.COLLECTION) {
64+
if(status.getType() == ObjectStatus.ObjectType.COLLECTION) {
8265
// Create directory in target
8366
IRODSFilesystem.createCollection(rcComm, targetPath);
84-
} else if (status.getType() == ObjectStatus.ObjectType.DATA_OBJECT) {
67+
}
68+
else if(status.getType() == ObjectStatus.ObjectType.DATA_OBJECT) {
8569
// Copy file
8670
IRODSFilesystem.copyDataObject(rcComm, entry.path(), targetPath);
8771
}
8872
}
8973
}
90-
74+
9175
@Override
9276
public EnumSet<Flags> features(final Path source, final Path target) {
9377
return EnumSet.of(Flags.recursive);

0 commit comments

Comments
 (0)