Skip to content

Commit

Permalink
Fix: Add missing open options handling for FTP byte channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Feb 12, 2024
1 parent 46acf58 commit 9f64707
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ object FtpFileSystemProvider : FileSystemProvider(), PathObservableProvider, Sea
} catch (e: IOException) {
throw e.toFileSystemExceptionForFtp(file.toString())
}
if (openOptions.createNew && fileFile != null) {
throw FileAlreadyExistsException(file.toString())
}
if (openOptions.noFollowLinks && fileFile != null && fileFile.isSymbolicLink) {
throw FileSystemException(
file.toString(), null, "File is a symbolic link: $fileFile"
)
}
if (openOptions.createNew && fileFile != null) {
throw FileAlreadyExistsException(file.toString())
}
if ((openOptions.create || openOptions.createNew) && fileFile == null) {
try {
Client.createFile(file)
Expand Down Expand Up @@ -221,6 +221,32 @@ object FtpFileSystemProvider : FileSystemProvider(), PathObservableProvider, Sea
if (openOptions.write && !openOptions.truncateExisting) {
throw UnsupportedOperationException("Missing ${StandardOpenOption.TRUNCATE_EXISTING}")
}
if (openOptions.write || openOptions.create || openOptions.createNew ||
openOptions.noFollowLinks) {
val fileFile = try {
Client.listFileOrNull(file, true)
} catch (e: IOException) {
throw e.toFileSystemExceptionForFtp(file.toString())
}
if (openOptions.createNew && fileFile != null) {
throw FileAlreadyExistsException(file.toString())
}
if (openOptions.noFollowLinks && fileFile != null && fileFile.isSymbolicLink) {
throw FileSystemException(
file.toString(), null, "File is a symbolic link: $fileFile"
)
}
if (fileFile == null) {
if (!(openOptions.create || openOptions.createNew)) {
throw NoSuchFileException(file.toString())
}
try {
Client.createFile(file)
} catch (e: IOException) {
throw e.toFileSystemExceptionForFtp(file.toString())
}
}
}
if (attributes.isNotEmpty()) {
throw UnsupportedOperationException(attributes.contentToString())
}
Expand Down

0 comments on commit 9f64707

Please sign in to comment.