mirror of
https://github.com/zhanghai/MaterialFiles
synced 2024-07-08 19:45:51 +00:00
Fix: Add missing open options handling for FTP byte channel.
This commit is contained in:
parent
46acf5894c
commit
9f647076fe
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user