Fix: Add missing open options handling for FTP byte channel.

This commit is contained in:
Hai Zhang 2024-02-11 23:14:52 -08:00
parent 46acf5894c
commit 9f647076fe

View File

@ -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)
@ -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())
}