Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Run other tests
working-directory: tests
run: |
tests=("command-line-options" "data-rep" "i18n_sjis" "jp-compat" "run" "syntax" "cobj-idx" "indexed-lock" "misc")
tests=("command-line-options" "data-rep" "i18n_sjis" "jp-compat" "run" "syntax" "cobj-idx" "file-lock" "misc")
for test in "${tests[@]}"; do
./"$test" || true
done
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- "syntax"
- "cobj-idx"
- "misc"
- "indexed-lock"
- "file-lock"
os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"]
uses: ./.github/workflows/test-other.yml
with:
Expand All @@ -75,7 +75,7 @@ jobs:
- "run"
- "syntax"
- "cobj-idx"
- "indexed-lock"
- "file-lock"
#- "misc"
os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"]
uses: ./.github/workflows/test-other.yml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- "run"
- "syntax"
- "cobj-idx"
- "indexed-lock"
- "file-lock"
- "misc"
os: ["ubuntu:24.04"]
uses: ./.github/workflows/test-other.yml
Expand All @@ -80,7 +80,7 @@ jobs:
- "run"
- "syntax"
- "cobj-idx"
- "indexed-lock"
- "file-lock"
#- "misc"
os: ["ubuntu:24.04"]
uses: ./.github/workflows/test-other.yml
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tests/jp-compat
tests/cobj-idx
tests/misc
tests/run
tests/indexed-lock
tests/file-lock
tests/*.log
tests/syntax
tests/cobol85/*/*.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,13 +1210,13 @@ public int open_(String filename, int mode, int sharing) throws IOException {
FileLock fl = null;
if (!filename.startsWith("/dev/")) {
try {
boolean lockFlag;
boolean isSharedLock;
if (sharing != 0 || mode == COB_OPEN_OUTPUT) {
lockFlag = false;
isSharedLock = false;
} else {
lockFlag = true;
isSharedLock = true;
}
fl = fp.tryLock(0L, Long.MAX_VALUE, lockFlag);
fl = fp.tryLock(0L, Long.MAX_VALUE, isSharedLock);
} catch (NonWritableChannelException e) {
fp.close();
return EBADF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField;

Expand Down Expand Up @@ -140,12 +139,7 @@ public int open_(String filename, int mode, int sharing) throws IOException {
this.fp.seek(0);
break;
case COB_OPEN_OUTPUT:
Path path = Paths.get(filename);
if (Files.exists(path)) {
Files.delete(path);
}
this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw");
this.fp.seek(0);
break;
case COB_OPEN_I_O:
this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw");
Expand Down Expand Up @@ -175,13 +169,13 @@ public int open_(String filename, int mode, int sharing) throws IOException {
FileLock fl = null;
if (!filename.startsWith("/dev/")) {
try {
boolean lockFlag;
boolean isSharedLock;
if (sharing != 0 || mode == COB_OPEN_OUTPUT) {
lockFlag = false;
isSharedLock = false;
} else {
lockFlag = true;
isSharedLock = true;
}
fl = ch.tryLock(0L, Long.MAX_VALUE, lockFlag);
fl = ch.tryLock(0L, Long.MAX_VALUE, isSharedLock);
} catch (NonWritableChannelException e) {
this.fp.close();
return EBADF;
Expand All @@ -198,6 +192,11 @@ public int open_(String filename, int mode, int sharing) throws IOException {
}
}

if(mode == COB_OPEN_OUTPUT) {
this.fp.setLength(0);
this.fp.seek(0);
}

this.file.setRandomAccessFile(this.fp, fl);
if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) {
if (this.file_linage_check()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void setRandomAccessFile(RandomAccessFile ra, FileLock fl) {
this.useStdOut = false;
this.useStdIn = false;
this.fc = ra.getChannel();
this.fl = fl;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ run~
syntax~
command-line-options~
cobj-idx~
indexed-lock~
file-lock~
*.dir
30 changes: 15 additions & 15 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TESTS = syntax \
jp-compat \
command-line-options \
cobj-idx \
indexed-lock \
file-lock \
misc
else
TESTS = syntax \
Expand All @@ -42,7 +42,7 @@ TESTS = syntax \
jp-compat \
command-line-options \
cobj-idx \
indexed-lock \
file-lock \
misc
endif

Expand Down Expand Up @@ -209,18 +209,18 @@ cobj_idx_DEPENDENCIES = \
cobj-idx.src/misc.at

indexed_lock_DEPENDENCIES = \
indexed-lock.at \
indexed-lock.src/file-lock.at \
indexed-lock.src/access-same-record.at \
indexed-lock.src/access-different-record.at \
indexed-lock.src/input-mode.at \
indexed-lock.src/same-process.at \
indexed-lock.src/open-start-write-rewrite.at \
indexed-lock.src/release-lock.at \
indexed-lock.src/open-input.at \
indexed-lock.src/lock-mode-clause.at \
indexed-lock.src/old-file.at \
indexed-lock.src/lock-mode-automatic.at
file-lock.at \
file-lock.src/lock-file.at \
file-lock.src/access-same-record.at \
file-lock.src/access-different-record.at \
file-lock.src/input-mode.at \
file-lock.src/same-process.at \
file-lock.src/open-start-write-rewrite.at \
file-lock.src/release-lock.at \
file-lock.src/open-input.at \
file-lock.src/lock-mode-clause.at \
file-lock.src/old-file.at \
file-lock.src/lock-mode-automatic.at

misc_DEPENDENCIES = \
misc.src/signed-comp3.at \
Expand Down Expand Up @@ -305,5 +305,5 @@ $(srcdir)/i18n_sjis: $(i18n_sjis_DEPENDENCIES)
$(srcdir)/jp-compat: $(jp_compat_DEPENDENCIES)
$(srcdir)/command-line-options: $(command_line_options_DEPENDENCIES)
$(srcdir)/cobj-idx: $(cobj_idx_DEPENDENCIES)
$(srcdir)/indexed-lock: $(indexed_lock_DEPENDENCIES)
$(srcdir)/file-lock: $(indexed_lock_DEPENDENCIES)
$(srcdir)/misc: $(misc_DEPENDENCIES)
36 changes: 18 additions & 18 deletions tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ SUBDIRS = cobol85
@I18N_UTF8_FALSE@ jp-compat \
@I18N_UTF8_FALSE@ command-line-options \
@I18N_UTF8_FALSE@ cobj-idx \
@I18N_UTF8_FALSE@ indexed-lock \
@I18N_UTF8_FALSE@ file-lock \
@I18N_UTF8_FALSE@ misc

@I18N_UTF8_TRUE@TESTS = syntax \
Expand All @@ -582,7 +582,7 @@ SUBDIRS = cobol85
@I18N_UTF8_TRUE@ jp-compat \
@I18N_UTF8_TRUE@ command-line-options \
@I18N_UTF8_TRUE@ cobj-idx \
@I18N_UTF8_TRUE@ indexed-lock \
@I18N_UTF8_TRUE@ file-lock \
@I18N_UTF8_TRUE@ misc

syntax_DEPENDENCIES = \
Expand Down Expand Up @@ -748,18 +748,18 @@ cobj_idx_DEPENDENCIES = \
cobj-idx.src/misc.at

indexed_lock_DEPENDENCIES = \
indexed-lock.at \
indexed-lock.src/file-lock.at \
indexed-lock.src/access-same-record.at \
indexed-lock.src/access-different-record.at \
indexed-lock.src/input-mode.at \
indexed-lock.src/same-process.at \
indexed-lock.src/open-start-write-rewrite.at \
indexed-lock.src/release-lock.at \
indexed-lock.src/open-input.at \
indexed-lock.src/lock-mode-clause.at \
indexed-lock.src/old-file.at \
indexed-lock.src/lock-mode-automatic.at
file-lock.at \
file-lock.src/lock-file.at \
file-lock.src/access-same-record.at \
file-lock.src/access-different-record.at \
file-lock.src/input-mode.at \
file-lock.src/same-process.at \
file-lock.src/open-start-write-rewrite.at \
file-lock.src/release-lock.at \
file-lock.src/open-input.at \
file-lock.src/lock-mode-clause.at \
file-lock.src/old-file.at \
file-lock.src/lock-mode-automatic.at

misc_DEPENDENCIES = \
misc.src/signed-comp3.at \
Expand Down Expand Up @@ -1159,9 +1159,9 @@ cobj-idx.log: cobj-idx
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
indexed-lock.log: indexed-lock
@p='indexed-lock'; \
b='indexed-lock'; \
file-lock.log: file-lock
@p='file-lock'; \
b='file-lock'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
Expand Down Expand Up @@ -1407,7 +1407,7 @@ $(srcdir)/i18n_sjis: $(i18n_sjis_DEPENDENCIES)
$(srcdir)/jp-compat: $(jp_compat_DEPENDENCIES)
$(srcdir)/command-line-options: $(command_line_options_DEPENDENCIES)
$(srcdir)/cobj-idx: $(cobj_idx_DEPENDENCIES)
$(srcdir)/indexed-lock: $(indexed_lock_DEPENDENCIES)
$(srcdir)/file-lock: $(indexed_lock_DEPENDENCIES)
$(srcdir)/misc: $(misc_DEPENDENCIES)

# Tell versions [3.59,3.63) of GNU make to not export all variables.
Expand Down
4 changes: 2 additions & 2 deletions tests/indexed-lock.at → tests/file-lock.at
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AT_INIT([indexed-lock])
AT_INIT([file-lock])

m4_include([file-lock.at])
m4_include([lock-file.at])
m4_include([access-same-record.at])
m4_include([access-different-record.at])
m4_include([input-mode.at])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE"
])


AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .])
AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .])
AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .])
AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .])

AT_DATA([prog1.template.cbl], [
IDENTIFICATION DIVISION.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE"
])


AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .])
AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .])
AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .])
AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .])

AT_DATA([prog1.template.cbl], [
IDENTIFICATION DIVISION.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD
])


AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .])
AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .])
AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .])
AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .])

AT_DATA([prog1.template.cbl], [
IDENTIFICATION DIVISION.
Expand Down
Loading
Loading