1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Use Android separator instead of homemade one

This commit is contained in:
Hannes Achleitner 2020-06-24 09:00:02 +02:00
parent d28927712c
commit 070ac89fa9
9 changed files with 22 additions and 29 deletions

View File

@ -41,6 +41,7 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import okhttp3.Cookie; import okhttp3.Cookie;
import timber.log.Timber; import timber.log.Timber;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -249,7 +250,7 @@ public class AccountUtils {
.domain(serverUri.getHost()) .domain(serverUri.getHost())
.path( .path(
serverUri.getPath().equals("") serverUri.getPath().equals("")
? FileUtils.PATH_SEPARATOR ? File.separator
: serverUri.getPath() : serverUri.getPath()
) )
.build()); .build());

View File

@ -29,12 +29,11 @@ import timber.log.Timber;
import java.io.File; import java.io.File;
public class FileUtils { public class FileUtils {
public static final String PATH_SEPARATOR = "/";
public static final String FINAL_CHUNKS_FILE = ".file"; public static final String FINAL_CHUNKS_FILE = ".file";
static String getParentPath(String remotePath) { static String getParentPath(String remotePath) {
String parentPath = new File(remotePath).getParent(); String parentPath = new File(remotePath).getParent();
parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR; parentPath = parentPath.endsWith(File.separator) ? parentPath : parentPath + File.separator;
return parentPath; return parentPath;
} }
@ -42,14 +41,12 @@ public class FileUtils {
* Validate the fileName to detect if contains any forbidden character: / , \ , < , > , * Validate the fileName to detect if contains any forbidden character: / , \ , < , > ,
* : , " , | , ? , * * : , " , | , ? , *
* *
* @param fileName
* @return
*/ */
public static boolean isValidName(String fileName) { public static boolean isValidName(String fileName) {
boolean result = true; boolean result = true;
Timber.d("fileName =======%s", fileName); Timber.d("fileName =======%s", fileName);
if (fileName.contains(PATH_SEPARATOR)) { if (fileName.contains(File.separator)) {
result = false; result = false;
} }
return result; return result;

View File

@ -41,6 +41,7 @@ import at.bitfire.dav4android.property.owncloud.OCPermissions;
import at.bitfire.dav4android.property.owncloud.OCPrivatelink; import at.bitfire.dav4android.property.owncloud.OCPrivatelink;
import at.bitfire.dav4android.property.owncloud.OCSize; import at.bitfire.dav4android.property.owncloud.OCSize;
import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
@ -92,13 +93,13 @@ public class RemoteFile implements Parcelable, Serializable {
/** /**
* Create new {@link RemoteFile} with given path. * Create new {@link RemoteFile} with given path.
* <p> * <p>
* The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'. * The path received must be URL-decoded. Path separator must be File.separator, and it must be the first character in 'path'.
* *
* @param path The remote path of the file. * @param path The remote path of the file.
*/ */
public RemoteFile(String path) { public RemoteFile(String path) {
resetData(); resetData();
if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) { if (path == null || path.length() <= 0 || !path.startsWith(File.separator)) {
throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path); throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
} }
mRemotePath = path; mRemotePath = path;

View File

@ -68,11 +68,10 @@ public class RenameRemoteFileOperation extends RemoteOperation {
mNewName = newName; mNewName = newName;
String parent = (new File(mOldRemotePath)).getParent(); String parent = (new File(mOldRemotePath)).getParent();
parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + parent = (parent.endsWith(File.separator)) ? parent : parent + File.separator;
FileUtils.PATH_SEPARATOR;
mNewRemotePath = parent + mNewName; mNewRemotePath = parent + mNewName;
if (isFolder) { if (isFolder) {
mNewRemotePath += FileUtils.PATH_SEPARATOR; mNewRemotePath += File.separator;
} }
} }

View File

@ -82,14 +82,12 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
} }
long offset = 0; long offset = 0;
String uriPrefix = client.getUploadsWebDavUri() + FileUtils.PATH_SEPARATOR + String.valueOf(mTransferId); String uriPrefix = client.getUploadsWebDavUri() + File.separator + mTransferId;
long totalLength = fileToUpload.length(); long totalLength = fileToUpload.length();
long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE); long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE);
for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) { for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) {
mPutMethod = new PutMethod( mPutMethod = new PutMethod(new URL(uriPrefix + File.separator + chunkIndex));
new URL(uriPrefix + FileUtils.PATH_SEPARATOR + chunkIndex)
);
if (mRequiredEtag != null && mRequiredEtag.length() > 0) { if (mRequiredEtag != null && mRequiredEtag.length() > 0) {
mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\"");

View File

@ -25,6 +25,7 @@
package com.owncloud.android.lib.resources.shares package com.owncloud.android.lib.resources.shares
import com.owncloud.android.lib.resources.files.FileUtils import com.owncloud.android.lib.resources.files.FileUtils
import java.io.File
/** /**
* Contains the data of a Share from the Share API * Contains the data of a Share from the Share API
@ -48,7 +49,7 @@ data class RemoteShare(
var permissions: Int = DEFAULT_PERMISSION, var permissions: Int = DEFAULT_PERMISSION,
var sharedDate: Long = INIT_SHARED_DATE, var sharedDate: Long = INIT_SHARED_DATE,
var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS, var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS,
var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR), var isFolder: Boolean = path.endsWith(File.separator),
var userId: Long = 0, var userId: Long = 0,
val isValid: Boolean = id > -1 val isValid: Boolean = id > -1
) { ) {

View File

@ -25,14 +25,11 @@
package com.owncloud.android.lib.resources.shares package com.owncloud.android.lib.resources.shares
import android.util.Xml import android.util.Xml
import com.owncloud.android.lib.common.network.WebdavUtils import com.owncloud.android.lib.common.network.WebdavUtils
import com.owncloud.android.lib.resources.files.FileUtils
import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParser
import org.xmlpull.v1.XmlPullParserException import org.xmlpull.v1.XmlPullParserException
import org.xmlpull.v1.XmlPullParserFactory import org.xmlpull.v1.XmlPullParserFactory
import java.io.File
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.util.ArrayList import java.util.ArrayList
@ -330,9 +327,9 @@ class ShareXMLParser {
private fun fixPathForFolder(share: RemoteShare) { private fun fixPathForFolder(share: RemoteShare) {
if (share.isFolder && share.path.isNotEmpty() && if (share.isFolder && share.path.isNotEmpty() &&
!share.path.endsWith(FileUtils.PATH_SEPARATOR) !share.path.endsWith(File.separator)
) { ) {
share.path = share.path + FileUtils.PATH_SEPARATOR share.path = share.path + File.separator
} }
} }

View File

@ -30,8 +30,8 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
import com.owncloud.android.lib.common.network.WebdavUtils import com.owncloud.android.lib.common.network.WebdavUtils
import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR
import timber.log.Timber import timber.log.Timber
import java.io.File
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.net.URL import java.net.URL
@ -49,7 +49,7 @@ class GetRemoteUserAvatarOperation(private val avatarDimension: Int) : RemoteOpe
try { try {
val endPoint = val endPoint =
client.baseUri.toString() + NON_OFFICIAL_AVATAR_PATH + client.credentials.username + PATH_SEPARATOR + avatarDimension client.baseUri.toString() + NON_OFFICIAL_AVATAR_PATH + client.credentials.username + File.separator + avatarDimension
Timber.d("avatar URI: %s", endPoint) Timber.d("avatar URI: %s", endPoint)
val getMethod = GetMethod(URL(endPoint)) val getMethod = GetMethod(URL(endPoint))

View File

@ -47,7 +47,6 @@ import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation; import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation; import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation; import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
@ -151,14 +150,14 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
} }
private void startRefresh() { private void startRefresh() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR); ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(File.separator);
refreshOperation.execute(mClient, this, mHandler); refreshOperation.execute(mClient, this, mHandler);
} }
private void startUpload() { private void startUpload() {
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0]; File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = File.separator + fileToUpload.getName();
String mimeType = getString(R.string.sample_file_mimetype); String mimeType = getString(R.string.sample_file_mimetype);
// Get the last modification date of the file from the file system // Get the last modification date of the file from the file system
@ -174,7 +173,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private void startRemoteDeletion() { private void startRemoteDeletion() {
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0]; File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = File.separator + fileToUpload.getName();
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
removeOperation.execute(mClient, this, mHandler); removeOperation.execute(mClient, this, mHandler);
@ -185,7 +184,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
downFolder.mkdir(); downFolder.mkdir();
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0]; File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = File.separator + fileToUpload.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath,
downFolder.getAbsolutePath()); downFolder.getAbsolutePath());