1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 07:56:19 +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 timber.log.Timber;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -249,7 +250,7 @@ public class AccountUtils {
.domain(serverUri.getHost())
.path(
serverUri.getPath().equals("")
? FileUtils.PATH_SEPARATOR
? File.separator
: serverUri.getPath()
)
.build());

View File

@ -29,12 +29,11 @@ import timber.log.Timber;
import java.io.File;
public class FileUtils {
public static final String PATH_SEPARATOR = "/";
public static final String FINAL_CHUNKS_FILE = ".file";
static String getParentPath(String remotePath) {
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;
}
@ -42,14 +41,12 @@ public class FileUtils {
* Validate the fileName to detect if contains any forbidden character: / , \ , < , > ,
* : , " , | , ? , *
*
* @param fileName
* @return
*/
public static boolean isValidName(String fileName) {
boolean result = true;
Timber.d("fileName =======%s", fileName);
if (fileName.contains(PATH_SEPARATOR)) {
if (fileName.contains(File.separator)) {
result = false;
}
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.OCSize;
import java.io.File;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@ -92,13 +93,13 @@ public class RemoteFile implements Parcelable, Serializable {
/**
* Create new {@link RemoteFile} with given path.
* <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.
*/
public RemoteFile(String path) {
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);
}
mRemotePath = path;

View File

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

View File

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

View File

@ -25,6 +25,7 @@
package com.owncloud.android.lib.resources.shares
import com.owncloud.android.lib.resources.files.FileUtils
import java.io.File
/**
* Contains the data of a Share from the Share API
@ -48,7 +49,7 @@ data class RemoteShare(
var permissions: Int = DEFAULT_PERMISSION,
var sharedDate: Long = INIT_SHARED_DATE,
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,
val isValid: Boolean = id > -1
) {

View File

@ -25,14 +25,11 @@
package com.owncloud.android.lib.resources.shares
import android.util.Xml
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.XmlPullParserException
import org.xmlpull.v1.XmlPullParserFactory
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.util.ArrayList
@ -330,9 +327,9 @@ class ShareXMLParser {
private fun fixPathForFolder(share: RemoteShare) {
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.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR
import timber.log.Timber
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.net.URL
@ -49,7 +49,7 @@ class GetRemoteUserAvatarOperation(private val avatarDimension: Int) : RemoteOpe
try {
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)
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.RemoteOperationResult;
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.RemoteFile;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
@ -151,14 +150,14 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
}
private void startRefresh() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(File.separator);
refreshOperation.execute(mClient, this, mHandler);
}
private void startUpload() {
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
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);
// 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() {
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
String remotePath = File.separator + fileToUpload.getName();
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
removeOperation.execute(mClient, this, mHandler);
@ -185,7 +184,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
downFolder.mkdir();
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
String remotePath = File.separator + fileToUpload.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath,
downFolder.getAbsolutePath());