Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,37 @@ public static void main(String[] args) {
System.exit(1);
}
} else if ("migrate".equals(subCommand)) {
if (unrecognizedArgs.length != 2) {
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
} else {
System.err.println("error: too many indexed files are specified.");
}
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
System.exit(1);
}
String indexedFilePath = unrecognizedArgs[1];
try {
migrateIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
System.exit(1);
boolean hasError = false;
for (int i = 1; i < unrecognizedArgs.length; i++) {
String indexedFilePath = unrecognizedArgs[i];
try {
migrateIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
hasError = true;
}
}
System.exit(0);
System.exit(hasError ? 1 : 0);
} else if ("unlock".equals(subCommand)) {
if (unrecognizedArgs.length != 2) {
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
} else {
System.err.println("error: too many indexed files are specified.");
}
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
System.exit(1);
}
String indexedFilePath = unrecognizedArgs[1];
try {
unlockIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
System.exit(1);
boolean hasError = false;
for (int i = 1; i < unrecognizedArgs.length; i++) {
String indexedFilePath = unrecognizedArgs[i];
try {
unlockIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
hasError = true;
}
}
System.exit(0);
System.exit(hasError ? 1 : 0);
} else if ("load".equals(subCommand)) {
if (unrecognizedArgs.length < 2 || unrecognizedArgs.length > 3) {
if (unrecognizedArgs.length < 2) {
Expand Down Expand Up @@ -260,12 +258,12 @@ private static void printHelpMessage() {
" Write the records stored in the indexed file into the output file.");
System.out.println(" The default format of the output data is SEQUENTIAL of COBOL.");
System.out.println();
System.out.println("cobj-idx migrate <indexed file>");
System.out.println("cobj-idx migrate <indexed file> [<indexed file>...]");
System.out.println(
" Migrate the indexed file whose version is older than 1.1.12 to the latest"
+ " version.");
System.out.println();
System.out.println("cobj-idx unlock <indexed file>");
System.out.println("cobj-idx unlock <indexed file> [<indexed file>...]");
System.out.println(" Unlock all locks of the indexed file.");
System.out.println();
System.out.println("Options:");
Expand Down
6 changes: 6 additions & 0 deletions tests/cobj-idx.src/migrate.at
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@ AAAA2BBBB1CCCC1
AAAA1BBBB1CCCC1
AAAA3BBBB3CCCC3
])

# Test migrate with multiple files
AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file2.dat])
AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file3.dat])
AT_CHECK([${COBJ_IDX} migrate indexed_file2.dat indexed_file3.dat])

AT_CLEANUP
13 changes: 13 additions & 0 deletions tests/cobj-idx.src/unlock.at
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,17 @@ AT_CHECK([java check_record_lock], [0],
[00
])

# Test unlock with multiple files
AT_CHECK([rm -f indexed_file.dat indexed_file2.dat])
# Create multiple locked files
AT_CHECK([java create_and_exit])
AT_CHECK([cp indexed_file.dat indexed_file2.dat])
AT_CHECK([java create_and_exit]) # This will leave indexed_file.dat locked
# Unlock multiple files
AT_CHECK([${COBJ_IDX} unlock indexed_file.dat indexed_file2.dat])
# Check both files are unlocked
AT_CHECK([java check_file_lock], [0],
[00
])

AT_CLEANUP
Loading