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
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
383
384
53 changes: 39 additions & 14 deletions src/main/java/com/owncloud/android/datamodel/SyncedFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class SyncedFolder implements Serializable, Cloneable {
private boolean subfolderByDate;
private String account;
private int uploadAction;
private int nameCollisionPolicy;
private boolean enabled;
private long enabledTimestampMs;
private MediaFolderType type;
Expand All @@ -48,18 +49,19 @@ public class SyncedFolder implements Serializable, Cloneable {
/**
* constructor for new, to be persisted entity.
*
* @param localPath local path
* @param remotePath remote path
* @param wifiOnly upload on wifi only flag
* @param chargingOnly upload on charging only
* @param existing upload existing files
* @param subfolderByDate create sub-folders by date (month)
* @param account the account owning the synced folder
* @param uploadAction the action to be done after the upload
* @param enabled flag if synced folder config is active
* @param timestampMs the current timestamp in milliseconds
* @param type the type of the folder
* @param hidden hide item flag
* @param localPath local path
* @param remotePath remote path
* @param wifiOnly upload on wifi only flag
* @param chargingOnly upload on charging only
* @param existing upload existing files
* @param subfolderByDate create sub-folders by date (month)
* @param account the account owning the synced folder
* @param uploadAction the action to be done after the upload
* @param nameCollisionPolicy the behaviour to follow if detecting a collision
* @param enabled flag if synced folder config is active
* @param timestampMs the current timestamp in milliseconds
* @param type the type of the folder
* @param hidden hide item flag
*/
public SyncedFolder(String localPath,
String remotePath,
Expand All @@ -69,12 +71,25 @@ public SyncedFolder(String localPath,
boolean subfolderByDate,
String account,
int uploadAction,
int nameCollisionPolicy,
boolean enabled,
long timestampMs,
MediaFolderType type,
boolean hidden) {
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account,
uploadAction, enabled, timestampMs, type, hidden);
this(UNPERSISTED_ID,
localPath,
remotePath,
wifiOnly,
chargingOnly,
existing,
subfolderByDate,
account,
uploadAction,
nameCollisionPolicy,
enabled,
timestampMs,
type,
hidden);
}

/**
Expand All @@ -91,6 +106,7 @@ protected SyncedFolder(long id,
boolean subfolderByDate,
String account,
int uploadAction,
int nameCollisionPolicy,
boolean enabled,
long timestampMs,
MediaFolderType type,
Expand All @@ -104,6 +120,7 @@ protected SyncedFolder(long id,
this.subfolderByDate = subfolderByDate;
this.account = account;
this.uploadAction = uploadAction;
this.nameCollisionPolicy = nameCollisionPolicy;
this.setEnabled(enabled, timestampMs);
this.type = type;
this.hidden = hidden;
Expand Down Expand Up @@ -161,6 +178,10 @@ public int getUploadAction() {
return this.uploadAction;
}

public int getNameCollisionPolicy() {
return this.nameCollisionPolicy;
}

public boolean isEnabled() {
return this.enabled;
}
Expand Down Expand Up @@ -213,6 +234,10 @@ public void setUploadAction(int uploadAction) {
this.uploadAction = uploadAction;
}

public void setNameCollisionPolicy(int nameCollisionPolicy) {
this.nameCollisionPolicy = nameCollisionPolicy;
}

public void setType(MediaFolderType type) {
this.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,28 @@ public SyncedFolderDisplayItem(long id,
boolean subfolderByDate,
String account,
int uploadAction,
int nameCollisionPolicy,
boolean enabled,
long timestampMs,
List<String> filePaths,
String folderName,
long numberOfFiles,
MediaFolderType type,
boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
super(id,
localPath,
remotePath,
wifiOnly,
chargingOnly,
existing,
subfolderByDate,
account,
uploadAction,
nameCollisionPolicy,
enabled,
timestampMs,
type,
hidden);
this.filePaths = filePaths;
this.folderName = folderName;
this.numberOfFiles = numberOfFiles;
Expand All @@ -83,11 +96,26 @@ public SyncedFolderDisplayItem(long id,
boolean subfolderByDate,
String account,
int uploadAction,
int nameCollisionPolicy,
boolean enabled,
long timestampMs,
String folderName, MediaFolderType type, boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
String folderName,
MediaFolderType type,
boolean hidden) {
super(id,
localPath,
remotePath,
wifiOnly,
chargingOnly,
existing,
subfolderByDate,
account,
uploadAction,
nameCollisionPolicy,
enabled,
timestampMs,
type,
hidden);
this.folderName = folderName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT));
int uploadAction = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION));
int nameCollisionPolicy = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY));
boolean enabled = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED)) == 1;
long enabledTimestampMs = cursor.getLong(cursor.getColumnIndex(
Expand All @@ -359,9 +361,20 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
boolean hidden = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN)) == 1;

syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, existing,
subfolderByDate, accountName, uploadAction, enabled, enabledTimestampMs,
type, hidden);
syncedFolder = new SyncedFolder(id,
localPath,
remotePath,
wifiOnly,
chargingOnly,
existing,
subfolderByDate,
accountName,
uploadAction,
nameCollisionPolicy,
enabled,
enabledTimestampMs,
type,
hidden);
}
return syncedFolder;
}
Expand All @@ -385,6 +398,8 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.isSubfolderByDate());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT, syncedFolder.getAccount());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION, syncedFolder.getUploadAction());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY,
syncedFolder.getNameCollisionPolicy());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().getId());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN, syncedFolder.isHidden());

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 54;
public static final int DB_VERSION = 55;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -230,6 +230,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String SYNCED_FOLDER_SUBFOLDER_BY_DATE = "subfolder_by_date";
public static final String SYNCED_FOLDER_ACCOUNT = "account";
public static final String SYNCED_FOLDER_UPLOAD_ACTION = "upload_option";
public static final String SYNCED_FOLDER_NAME_COLLISION_POLICY = "name_collision_policy";
public static final String SYNCED_FOLDER_HIDDEN = "hidden";

// Columns of external links table
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/owncloud/android/jobs/FilesSyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,25 @@ private void syncFolder(
SimpleDateFormat sFormatter,
SyncedFolder syncedFolder
) {
String remotePath;
boolean subfolderByDate;
Integer uploadAction;
boolean needsCharging;
boolean needsWifi;
File file;
ArbitraryDataProvider arbitraryDataProvider;
String accountName = syncedFolder.getAccount();
Optional<User> optionalUser = userAccountManager.getUser(accountName);
if (!optionalUser.isPresent()) {
return;
}
User user = optionalUser.get();

ArbitraryDataProvider arbitraryDataProvider = null;
if (lightVersion) {
arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
} else {
arbitraryDataProvider = null;
}

String remotePath;
boolean subfolderByDate;
Integer uploadAction;
FileUploader.NameCollisionPolicy nameCollisionPolicy;
boolean needsCharging;
boolean needsWifi;
File file;
for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
Long.toString(syncedFolder.getId()))) {
file = new File(path);
Expand All @@ -197,12 +196,15 @@ private void syncFolder(
SettingsActivity.SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI);
String uploadActionString = resources.getString(R.string.syncedFolder_light_upload_behaviour);
uploadAction = getUploadAction(uploadActionString);
nameCollisionPolicy = FileUploader.NameCollisionPolicy.ASK_USER;
subfolderByDate = resources.getBoolean(R.bool.syncedFolder_light_use_subfolders);
remotePath = resources.getString(R.string.syncedFolder_remote_folder);
} else {
needsCharging = syncedFolder.isChargingOnly();
needsWifi = syncedFolder.isWifiOnly();
uploadAction = syncedFolder.getUploadAction();
nameCollisionPolicy = FileUploader.NameCollisionPolicy.deserialize(
syncedFolder.getNameCollisionPolicy());
subfolderByDate = syncedFolder.isSubfolderByDate();
remotePath = syncedFolder.getRemotePath();
}
Expand All @@ -224,7 +226,7 @@ private void syncFolder(
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
needsWifi,
needsCharging,
FileUploader.NameCollisionPolicy.ASK_USER
nameCollisionPolicy
);

filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.owncloud.android.datamodel.SyncedFolder;
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.ShareType;
Expand Down Expand Up @@ -832,10 +833,11 @@ private void createSyncedFoldersTable(SQLiteDatabase db) {
+ ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, " // charging only
+ ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER, " // existing
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, " // enabled
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
+ ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
+ ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " TEXT, " // account
+ ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, " // upload action
+ ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER, " // name collision policy
+ ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER, " // type
+ ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER );" // hidden
);
Expand Down Expand Up @@ -2168,6 +2170,29 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}

if (oldVersion < 55 && newVersion >= 55) {
Log_OC.i(SQL, "Entering in the #55 add synced.name_collision_policy.");
db.beginTransaction();
try {
// Add synced.name_collision_policy
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER "); // integer

// make sure all existing folders set to FileUploader.NameCollisionPolicy.ASK_USER.
db.execSQL("UPDATE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " = " +
FileUploader.NameCollisionPolicy.ASK_USER.serialize());
upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}

if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
}
}
}
Loading