Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@

import java.lang.ref.WeakReference;

import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;


/**
* Async Task to verify the credentials of a user
*/
public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOperationResult> {

private static final String REMOTE_PATH = "/";
private static final boolean SUCCESS_IF_ABSENT = false;

private WeakReference<Context> mWeakContext;
Expand All @@ -66,7 +67,7 @@ protected RemoteOperationResult doInBackground(Object... params) {
client.setCredentials(credentials);

// Operation - try credentials
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(REMOTE_PATH, SUCCESS_IF_ABSENT);
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(ROOT_PATH, SUCCESS_IF_ABSENT);
result = operation.execute(client);

if (operation.wasRedirected()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
import lombok.Getter;
import lombok.Setter;

import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;

@Getter
public class FileDataStorageManager {
private static final String TAG = FileDataStorageManager.class.getSimpleName();
Expand Down Expand Up @@ -264,7 +266,7 @@ public boolean saveFile(OCFile file) {
* @return the parent file
*/
public OCFile saveFileWithParent(OCFile file, Context context) {
if (file.getParentId() == 0 && !"/".equals(file.getRemotePath())) {
if (file.getParentId() == 0 && !ROOT_PATH.equals(file.getRemotePath())) {
String remotePath = file.getRemotePath();
String parentPath = remotePath.substring(0, remotePath.lastIndexOf(file.getFileName()));

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ public String getRemotePath() {
if (isEncrypted() && !isFolder()) {
String parentPath = new File(remotePath).getParent();

if (parentPath.endsWith("/")) {
if (parentPath.endsWith(PATH_SEPARATOR)) {
return parentPath + getEncryptedFileName();
} else {
return parentPath + "/" + getEncryptedFileName();
return parentPath + PATH_SEPARATOR + getEncryptedFileName();
}
} else {
if (isFolder()) {
if (remotePath.endsWith("/")) {
if (remotePath.endsWith(PATH_SEPARATOR)) {
return remotePath;
} else {
return remotePath + "/";
return remotePath + PATH_SEPARATOR;
}
} else {
return remotePath;
Expand Down Expand Up @@ -412,7 +412,7 @@ private void resetData() {
*/
public String getParentRemotePath() {
String parentPath = new File(this.getRemotePath()).getParent();
return parentPath.endsWith("/") ? parentPath : parentPath + "/";
return parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

import androidx.annotation.NonNull;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;

/**
* Database provider for handling the persistence aspects of {@link SyncedFolder}s.
*/
Expand Down Expand Up @@ -251,7 +253,7 @@ public void updateAutoUploadPaths(Context context) {
for (SyncedFolder syncedFolder : syncedFolders) {
if (!new File(syncedFolder.getLocalPath()).exists()) {
String localPath = syncedFolder.getLocalPath();
if (localPath.endsWith("/")) {
if (localPath.endsWith(PATH_SEPARATOR)) {
localPath = localPath.substring(0, localPath.lastIndexOf('/'));
}
localPath = localPath.substring(0, localPath.lastIndexOf('/'));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/owncloud/android/jobs/FilesSyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;

/*
Job that:
- restarts existing jobs if required
Expand Down Expand Up @@ -190,7 +192,7 @@ private void syncFolder(Context context, Resources resources, boolean lightVersi
if (!subfolderByDate) {
String adaptedPath = file.getAbsolutePath()
.replace(syncedFolder.getLocalPath(), "")
.replace("/" + file.getName(), "");
.replace(PATH_SEPARATOR + file.getName(), "");
remotePath += adaptedPath;
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/owncloud/android/jobs/OfflineSyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@

import androidx.annotation.NonNull;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;

public class OfflineSyncJob extends Job {
public static final String TAG = "OfflineSyncJob";

Expand Down Expand Up @@ -90,7 +93,7 @@ protected Result onRunJob(@NonNull Params params) {
FileDataStorageManager storageManager = new FileDataStorageManager(account,
getContext().getContentResolver());

OCFile ocRoot = storageManager.getFileByPath("/");
OCFile ocRoot = storageManager.getFileByPath(ROOT_PATH);

if (ocRoot.getStoragePath() == null) {
break;
Expand All @@ -109,7 +112,7 @@ protected Result onRunJob(@NonNull Params params) {

private void recursive(File folder, FileDataStorageManager storageManager, Account account) {
String downloadFolder = FileStorageUtils.getSavePath(account.name);
String folderName = folder.getAbsolutePath().replaceFirst(downloadFolder, "") + "/";
String folderName = folder.getAbsolutePath().replaceFirst(downloadFolder, "") + PATH_SEPARATOR;
Log_OC.d(TAG, folderName + ": enter");

// exit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeType;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;


/**
* Access to remote operation performing the creation of a new folder in the ownCloud server.
Expand Down Expand Up @@ -99,13 +102,13 @@ private void saveFolderInDB() {
getFileByPath(FileStorageUtils.getParentPath(mRemotePath)) == null){// When parent
// of remote path
// is not created
String[] subFolders = mRemotePath.split("/");
String composedRemotePath = "/";
String[] subFolders = mRemotePath.split(PATH_SEPARATOR);
String composedRemotePath = ROOT_PATH;

// For each ancestor folders create them recursively
for (String subFolder : subFolders) {
if (!subFolder.isEmpty()) {
composedRemotePath = composedRemotePath + subFolder + "/";
composedRemotePath = composedRemotePath + subFolder + PATH_SEPARATOR;
mRemotePath = composedRemotePath;
saveFolderInDB();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@

import dagger.android.AndroidInjection;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;

@TargetApi(Build.VERSION_CODES.KITKAT)
public class DocumentsStorageProvider extends DocumentsProvider {

Expand Down Expand Up @@ -396,7 +399,7 @@ public String copyDocument(String sourceDocumentId, String targetParentDocumentI
String newPath = targetFolder.getRemotePath() + file.getFileName();

if (file.isFolder()) {
newPath = newPath + "/";
newPath = newPath + PATH_SEPARATOR;
}
OCFile newFile = currentStorageManager.getFileByPath(newPath);

Expand Down Expand Up @@ -438,7 +441,7 @@ public String moveDocument(String sourceDocumentId, String sourceParentDocumentI
public Cursor querySearchDocuments(String rootId, String query, String[] projection) {
updateCurrentStorageManagerIfNeeded(rootId);

OCFile root = currentStorageManager.getFileByPath("/");
OCFile root = currentStorageManager.getFileByPath(ROOT_PATH);
FileCursor result = new FileCursor(projection);

for (OCFile f : findFiles(root, query)) {
Expand Down Expand Up @@ -469,7 +472,7 @@ public String createDocument(String documentId, String mimeType, String displayN
private String createFolder(OCFile parent, String displayName, String documentId) throws FileNotFoundException {

CreateFolderOperation createFolderOperation = new CreateFolderOperation(parent.getRemotePath() + displayName
+ "/", true);
+ PATH_SEPARATOR, true);
RemoteOperationResult result = createFolderOperation.execute(client, currentStorageManager);


Expand All @@ -479,7 +482,7 @@ private String createFolder(OCFile parent, String displayName, String documentId
}


String newDirPath = parent.getRemotePath() + displayName + "/";
String newDirPath = parent.getRemotePath() + displayName + PATH_SEPARATOR;
OCFile newFolder = currentStorageManager.getFileByPath(newDirPath);

return String.valueOf(newFolder.getFileId());
Expand Down Expand Up @@ -601,7 +604,7 @@ private void initiateStorageMap() throws FileNotFoundException {

for (Account account : accountManager.getAccounts()) {
final FileDataStorageManager storageManager = new FileDataStorageManager(account, contentResolver);
final OCFile rootDir = storageManager.getFileByPath("/");
final OCFile rootDir = storageManager.getFileByPath(ROOT_PATH);
rootIdToStorageManager.put(rootDir.getFileId(), storageManager);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;

/**
* Displays, what files the user has available in his ownCloud. This is the main view.
*/
Expand Down Expand Up @@ -983,7 +985,7 @@ public void onCheckAvailableSpaceFinish(boolean hasEnoughSpaceAvailable, String.

if (hasEnoughSpaceAvailable) {
File file = new File(filesToUpload[0]);
File renamedFile = new File(file.getParent() + "/" + FileOperationsHelper.getCapturedImageName());
File renamedFile = new File(file.getParent() + PATH_SEPARATOR + FileOperationsHelper.getCapturedImageName());

if (!file.renameTo(renamedFile)) {
DisplayUtils.showSnackMessage(getActivity(), "Fail to upload taken image!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@

import javax.inject.Inject;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;

/**
* This can be used to upload things to an ownCloud instance.
*/
Expand Down Expand Up @@ -174,7 +177,7 @@ protected void onCreate(Bundle savedInstanceState) {
String parentPath = savedInstanceState.getString(KEY_PARENTS);

if (parentPath != null) {
mParents.addAll(Arrays.asList(parentPath.split("/")));
mParents.addAll(Arrays.asList(parentPath.split(PATH_SEPARATOR)));
}

mFile = savedInstanceState.getParcelable(KEY_FILE);
Expand Down Expand Up @@ -884,7 +887,7 @@ private String generatePath(Stack<String> dirs) {
String full_path = "";

for (String a : dirs) {
full_path += a + "/";
full_path += a + PATH_SEPARATOR;
}
return full_path;
}
Expand Down Expand Up @@ -1034,10 +1037,10 @@ private void initTargetFolder() {
if (mParents.empty()) {
String lastPath = preferences.getLastUploadPath();
// "/" equals root-directory
if ("/".equals(lastPath)) {
if (ROOT_PATH.equals(lastPath)) {
mParents.add("");
} else {
String[] dir_names = lastPath.split("/");
String[] dir_names = lastPath.split(PATH_SEPARATOR);
mParents.clear();
mParents.addAll(Arrays.asList(dir_names));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
import butterknife.BindView;
import butterknife.ButterKnife;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;

/**
* Adapter for the trashbin view
*/
Expand Down Expand Up @@ -134,9 +137,9 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
String location;
int lastIndex = file.getOriginalLocation().lastIndexOf('/');
if (lastIndex != -1) {
location = "/" + file.getOriginalLocation().substring(0, lastIndex) + "/";
location = ROOT_PATH + file.getOriginalLocation().substring(0, lastIndex) + PATH_SEPARATOR;
} else {
location = "/";
location = ROOT_PATH;
}
trashbinFileViewHolder.originalLocation.setText(location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;

/**
* Custom edit text to support fixed suffix or prefix
*/
Expand All @@ -45,7 +47,7 @@ public CustomEditText(Context context, AttributeSet attrs) {

if (AuthenticatorActivity.DIRECTORY_SERVER_INPUT_TYPE.equals(serverInputType)) {
isPrefixFixed = true;
fixedText = getResources().getString(R.string.server_url) + "/";
fixedText = getResources().getString(R.string.server_url) + PATH_SEPARATOR;
} else if (AuthenticatorActivity.SUBDOMAIN_SERVER_INPUT_TYPE.equals(serverInputType)) {
isPrefixFixed = false;
fixedText = "." + getResources().getString(R.string.server_url);
Expand All @@ -56,18 +58,6 @@ public CustomEditText(Context context, AttributeSet attrs) {
}
}

public String getFullServerUrl() {
if (TextUtils.isEmpty(fixedText)
|| getText().toString().startsWith(AuthenticatorActivity.HTTP_PROTOCOL)
|| getText().toString().startsWith(AuthenticatorActivity.HTTPS_PROTOCOL)) {
return getText().toString();
} else if (isPrefixFixed) {
return getResources().getString(R.string.server_url) + "/" + getText().toString();
} else {
return getText().toString() + "." + getResources().getString(R.string.server_url);
}
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (!TextUtils.isEmpty(fixedText)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;

/**
* A Fragment that lists all files and folders in a given path.
* TODO refactor to get rid of direct dependency on FileDisplayActivity
Expand Down Expand Up @@ -796,7 +798,7 @@ public int onBrowseUp() {
parentDir = storageManager.getFileByPath(parentPath);
moveCount++;
} else {
parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH);
parentDir = storageManager.getFileByPath(ROOT_PATH);
}
while (parentDir == null) {
parentPath = new File(parentPath).getParent();
Expand Down Expand Up @@ -1140,7 +1142,7 @@ public void listDirectory(OCFile directory, boolean onlyOnDevice, boolean fromSe
if (mFile != null) {
directory = mFile;
} else {
directory = storageManager.getFileByPath("/");
directory = storageManager.getFileByPath(ROOT_PATH);
if (directory == null) {
return; // no files, wait for sync
}
Expand Down
Loading