FTP-Server: Add handling for checking folder name in setpath
This patch adds proper handling to check for name of folder to be set
or created using set folder operation. Name is now checked for exisitng
file name at same location, and error is returned to Client if exsiting
file with same name already exists.
Change-Id: I2a43e6b30767c922f53743e9019715518dfab312
CRs-Fixed: 605667
diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpObexServer.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpObexServer.java
index 2fdd0cb..5d05769 100644
--- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpObexServer.java
+++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpObexServer.java
@@ -653,6 +653,22 @@
Log.e(TAG, "path: " + current_path_tmp + " not found");
return ResponseCodes.OBEX_HTTP_NOT_FOUND;
}
+ } else {
+ /* Check if the folder to be created or set is not having same
+ * name as existing file in same location. If file with same name is
+ * present, return error to Client. */
+ File file = new File(current_path_tmp);
+ if (file.isFile()) {
+ if (create) {
+ Log.e(TAG, "File already exists with same name, " +
+ "can't create folder with same name");
+ return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
+ } else {
+ Log.e(TAG, "Path is not valid, path being set is " +
+ "for file not folder");
+ return ResponseCodes.OBEX_HTTP_NOT_FOUND;
+ }
+ }
}
} else if (current_path_tmp == null && tmp_path != null) {
if (create) {