Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhwanng committed May 1, 2024
1 parent e5ea479 commit ffdcd19
Show file tree
Hide file tree
Showing 23 changed files with 279 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@ public interface DirentDAO {
Single<List<DirentModel>> getAllByFullPath(String repo_id, String full_path);

@Query("select * from dirents where full_path = :full_path and repo_id = :repo_id limit 1")
DirentModel getByFullPathSync(String repo_id, String full_path);

@Query("select * from dirents where full_path = :full_path and repo_id = :repo_id limit 1")
DirentModel getByTargetPathSync(String repo_id, String full_path);

@Query("select * from dirents where uid = :uid")
Single<DirentModel> getDirentById(String uid);

@Query("select * from dirents where uid = :uid limit 1")
DirentModel getOneByIdSync(String uid);
List<DirentModel> getByFullPathSync(String repo_id, String full_path);

@Query("select * from dirents where uid in ( :uids )")
List<DirentModel> getListByIdsSync(List<String> uids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface EncKeyCacheDAO {
void insertAllSync(List<EncKeyCacheEntity> entities);

@Query("select * from enc_key_cache where repo_id = :repoId limit 1")
EncKeyCacheEntity getOneByRepoIdSync(String repoId);
List<EncKeyCacheEntity> getOneByRepoIdSync(String repoId);

@Query("select * from enc_key_cache where repo_id = :repoId limit 1")
Single<List<EncKeyCacheEntity>> getListByRepoIdAsync(String repoId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public interface FileTransferDAO {
Single<List<FileTransferEntity>> getListByFeatAsync(String related_account, List<TransferDataSource> feats);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1")
FileTransferEntity getOnePendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);
List<FileTransferEntity> getOnePendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit :limit")
List<FileTransferEntity> getListPendingTransferSync(String related_account, TransferAction transfer_action, int limit);


@Query("select * from file_transfer_list where transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1")
FileTransferEntity getOnePendingTransferAllAccountSync(TransferAction transfer_action, TransferDataSource feature);
List<FileTransferEntity> getOnePendingTransferAllAccountSync(TransferAction transfer_action, TransferDataSource feature);

@Query("select * from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc")
List<FileTransferEntity> getPendingDownloadListByActionSync(String related_account);
Expand All @@ -98,31 +98,23 @@ public interface FileTransferDAO {
List<FileTransferEntity> getDownloadListSync(String related_account);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and target_path = :target_path and data_status = 0 order by created_at desc limit 1")
FileTransferEntity getByTargetPathSync(String related_account, TransferAction transferAction, String target_path);
List<FileTransferEntity> getByTargetPathSync(String related_account, TransferAction transferAction, String target_path);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at desc limit 1")
FileTransferEntity getByFullPathSync(String related_account, TransferAction transferAction, String full_path);

@Query("select * from file_transfer_list where uid = :uid")
List<FileTransferEntity> getByUid(String uid);

@Query("select * from file_transfer_list where uid in ( :uids )")
List<FileTransferEntity> getListByUidsSync(List<String> uids);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source = 'ALBUM_BACKUP' and mime_type like :mime_type_str and data_status = 0 order by file_original_modified_at desc limit 1")
FileTransferEntity getLastOneForMedia(String related_account, String mime_type_str);

@Query("select * from file_transfer_list where repo_id = :repoId and full_path IN(:fullPaths) and transfer_action = :transfer_action order by created_at asc")
Single<List<FileTransferEntity>> getListByFullPathsAsync(String repoId, List<String> fullPaths, TransferAction transfer_action);

@Query("select * from file_transfer_list where repo_id = :repoId and full_path IN(:fullPaths) and transfer_action = :transfer_action order by created_at asc")
List<FileTransferEntity> getListByFullPathsSync(String repoId, List<String> fullPaths, TransferAction transfer_action);

@Query("select * from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action order by created_at asc limit 1")
FileTransferEntity getOneByFullPathSync(String repoId, String fullPath, TransferAction transfer_action);

@Query("select * from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action order by created_at asc limit 1")
Single<FileTransferEntity> getOneByFullPathAsync(String repoId, String fullPath, TransferAction transfer_action);
@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at")
List<FileTransferEntity> getListByFullPathsSync(String related_account, TransferAction transferAction, String full_path);

@Query("select COUNT(*) from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action and data_source = :feature and data_status = 0 ")
int checkOneByFullPath(String repoId, String fullPath, TransferAction transfer_action, TransferDataSource feature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.text.TextUtils;

import com.blankj.utilcode.util.GsonUtils;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.account.Account;
Expand All @@ -13,7 +15,9 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -129,27 +133,36 @@ public static String getAccountDir(Account account) {
* repo-id::::new-repo-name
* </p>
*/
private static String getSpecialRepoDirMapping(String repo_id) {
private static String getSpecialRepoDirMapping(Account account, String repo_id) {

Set<String> sets = DataStoreManager.getCommonInstance().readSetString(DataStoreKeys.DS_REPO_DIR_MAPPING);

for (String set : sets) {
String[] ss = StringUtils.split(set, DataStoreKeys.SEPARATOR);
if (repo_id.equals(ss[0])) {
return ss[1];
List<String> list = getRepoNameMaps(account);
for (String set : list) {
String[] sp = StringUtils.split(set, DataStoreKeys.SEPARATOR);
if (repo_id.equals(sp[0])) {
return sp[1];
}
}

return null;
}

private static boolean checkSpecialRepoDirMapping(String repo_name) {
public static List<String> getRepoNameMaps(Account account) {
String names = DataStoreManager.getInstanceByUser(account.getSignature()).readString(DataStoreKeys.DS_REPO_DIR_MAPPING);
Type listType = new TypeToken<List<String>>() {
}.getType();

Set<String> sets = DataStoreManager.getCommonInstance().readSetString(DataStoreKeys.DS_REPO_DIR_MAPPING);
List<String> list = GsonUtils.fromJson(names, listType);
if (null == list) {
list = new ArrayList<>();
}
return list;
}

for (String set : sets) {
String[] ss = StringUtils.split(set, DataStoreKeys.SEPARATOR);
if (repo_name.equals(ss[1])) {
private static boolean checkSpecialRepoDirMapping(Account account, String repo_name) {
List<String> list = getRepoNameMaps(account);
for (String set : list) {
String[] sp = StringUtils.split(set, DataStoreKeys.SEPARATOR);
if (repo_name.equals(sp[1])) {
return true;
}
}
Expand All @@ -161,7 +174,7 @@ public static File getRepoDirMappingDataStore(Account account, String repo_id, S

String accountDir = DataManager.getAccountDir(account);

String repoDirName = getSpecialRepoDirMapping(repo_id);
String repoDirName = getSpecialRepoDirMapping(account, repo_id);

File repoDir;
if (!TextUtils.isEmpty(repoDirName)) {
Expand All @@ -181,7 +194,7 @@ public static File getRepoDirMappingDataStore(Account account, String repo_id, S
uniqueRepoName = repo_name + " (" + i + ")";
}

boolean isDuplicate = checkSpecialRepoDirMapping(uniqueRepoName);
boolean isDuplicate = checkSpecialRepoDirMapping(account, uniqueRepoName);
repoDir = new File(accountDir, uniqueRepoName);
if (!repoDir.exists() && !isDuplicate) {
break;
Expand All @@ -196,9 +209,10 @@ public static File getRepoDirMappingDataStore(Account account, String repo_id, S
}


Set<String> sets = DataStoreManager.getCommonInstance().readSetString(DataStoreKeys.DS_REPO_DIR_MAPPING);
sets.add(repo_id + DataStoreKeys.SEPARATOR + uniqueRepoName);
DataStoreManager.getCommonInstance().writeSetString(DataStoreKeys.DS_REPO_DIR_MAPPING, sets);
List<String> list = getRepoNameMaps(account);
list.add(repo_id + DataStoreKeys.SEPARATOR + uniqueRepoName);
String v = GsonUtils.toJson(list);
DataStoreManager.getInstanceByUser(account.getSignature()).writeString(DataStoreKeys.DS_REPO_DIR_MAPPING, v);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public static DataStoreManager getInstanceByUser(String accountSignature) {
// file1.delete();
// }
// }

public void writeInteger(String strKey, Integer value) {
writeValue(strKey, value);
}
Expand Down Expand Up @@ -179,20 +178,20 @@ public void writeLong(String strKey, @NonNull Long value) {
writeValue(strKey, value);
}

public void writeSetString(String strKey, Set<String> value) {
if (null == value) {
value = new HashSet<>();
}
writeValue(strKey, value);
}
// public void writeSetString(String strKey, Set<String> value) {
// if (null == value) {
// value = new HashSet<>();
// }
// writeValue(strKey, value);
// }

/**
* write value
*/
private void writeValue(String strKey, Object value) {
// Single<Preferences> single = null;
if (value instanceof Integer) {
sharedPreferences.edit().putInt(strKey, (Integer) value).commit();
sharedPreferences.edit().putInt(strKey, (Integer) value).apply();

// Preferences.Key<Integer> intKey = PreferencesKeys.intKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
Expand All @@ -201,7 +200,7 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof String) {
sharedPreferences.edit().putString(strKey, (String) value).commit();
sharedPreferences.edit().putString(strKey, (String) value).apply();

// Preferences.Key<String> stringKey = PreferencesKeys.stringKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
Expand All @@ -211,7 +210,7 @@ private void writeValue(String strKey, Object value) {
// }
// );
} else if (value instanceof Boolean) {
sharedPreferences.edit().putBoolean(strKey, (Boolean) value).commit();
sharedPreferences.edit().putBoolean(strKey, (Boolean) value).apply();

// Preferences.Key<Boolean> booleanKey = PreferencesKeys.booleanKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
Expand All @@ -220,7 +219,7 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof Double) {
sharedPreferences.edit().putFloat(strKey, (Float) value).commit();
sharedPreferences.edit().putFloat(strKey, (Float) value).apply();

// Preferences.Key<Double> doubleKey = PreferencesKeys.doubleKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
Expand All @@ -229,7 +228,7 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof Float) {
sharedPreferences.edit().putFloat(strKey, (Float) value).commit();
sharedPreferences.edit().putFloat(strKey, (Float) value).apply();

// Preferences.Key<Float> floatKey = PreferencesKeys.floatKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
Expand All @@ -238,24 +237,27 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof Long) {
sharedPreferences.edit().putLong(strKey, (Long) value).commit();
sharedPreferences.edit().putLong(strKey, (Long) value).apply();

// Preferences.Key<Long> longKey = PreferencesKeys.longKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
// MutablePreferences mutablePreferences = preferences.toMutablePreferences();
// mutablePreferences.set(longKey, (Long) value);
// return Single.just(mutablePreferences);
// });
} else if (value instanceof Set) {
sharedPreferences.edit().putStringSet(strKey, (Set<String>) value).commit();

// Preferences.Key<Set<String>> setKey = PreferencesKeys.stringSetKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
// MutablePreferences mutablePreferences = preferences.toMutablePreferences();
// mutablePreferences.set(setKey, (Set<String>) value);
// return Single.just(mutablePreferences);
// });
} else {
}
// else if (value instanceof Set<?>) {
// Set<String> set = (Set<String>) value;
// sharedPreferences.edit().putStringSet(strKey, set).apply();
//
//// Preferences.Key<Set<String>> setKey = PreferencesKeys.stringSetKey(strKey);
//// single = dataStore.updateDataAsync(preferences -> {
//// MutablePreferences mutablePreferences = preferences.toMutablePreferences();
//// mutablePreferences.set(setKey, (Set<String>) value);
//// return Single.just(mutablePreferences);
//// });
// }
else {
throw new IllegalStateException("Unexpected value: " + value);
}

Expand Down Expand Up @@ -372,20 +374,20 @@ public long readLong(String key) {
}


public Set<String> readSetString(String key) {
return sharedPreferences.getStringSet(key, new HashSet<>());

// Preferences.Key<Set<String>> setKey = PreferencesKeys.stringSetKey(key);
// Flowable<Set<String>> flowable = dataStore.data().map(new Function<Preferences, Set<String>>() {
// @Override
// public Set<String> apply(Preferences preferences) throws Exception {
// Set<String> value = preferences.get(setKey);
// return value != null ? new HashSet<>(value) : new HashSet<>();
// }
// });
// public Set<String> readSetString(String key) {
// return sharedPreferences.getStringSet(key, new HashSet<>());
//
// return flowable.first(new HashSet<>()).blockingGet();
}
//// Preferences.Key<Set<String>> setKey = PreferencesKeys.stringSetKey(key);
//// Flowable<Set<String>> flowable = dataStore.data().map(new Function<Preferences, Set<String>>() {
//// @Override
//// public Set<String> apply(Preferences preferences) throws Exception {
//// Set<String> value = preferences.get(setKey);
//// return value != null ? new HashSet<>(value) : new HashSet<>();
//// }
//// });
////
//// return flowable.first(new HashSet<>()).blockingGet();
// }


// public void removeByStringKey(String strKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,12 @@ private void uploadBlockFile(Account account, FileTransferEntity transferEntity)
AppDatabase.getInstance().fileTransferDAO().update(transferEntity);

//
EncKeyCacheEntity encKeyCacheEntity = AppDatabase.getInstance().encKeyCacheDAO().getOneByRepoIdSync(transferEntity.repo_id);
if (encKeyCacheEntity == null) {
List<EncKeyCacheEntity> encKeyCacheEntityList = AppDatabase.getInstance().encKeyCacheDAO().getOneByRepoIdSync(transferEntity.repo_id);
if (CollectionUtils.isEmpty(encKeyCacheEntityList)) {
throw SeafException.encryptException;
}

EncKeyCacheEntity encKeyCacheEntity = encKeyCacheEntityList.get(0);
final String encKey = encKeyCacheEntity.enc_key;
final String encIv = encKeyCacheEntity.enc_iv;
if (TextUtils.isEmpty(encKey) || TextUtils.isEmpty(encIv)) {
Expand Down Expand Up @@ -560,8 +561,9 @@ private void updateSuccess(FileTransferEntity transferEntity, String fileId, Fil
AppDatabase.getInstance().fileTransferDAO().update(transferEntity);

//update
DirentModel direntModel = AppDatabase.getInstance().direntDao().getByFullPathSync(transferEntity.repo_id, transferEntity.full_path);
if (direntModel != null) {
List<DirentModel> direntList = AppDatabase.getInstance().direntDao().getByFullPathSync(transferEntity.repo_id, transferEntity.full_path);
if (!CollectionUtils.isEmpty(direntList)) {
DirentModel direntModel = direntList.get(0);
direntModel.last_modified_at = transferEntity.modified_at;
direntModel.id = fileId;
direntModel.size = transferEntity.file_size;
Expand Down
Loading

0 comments on commit ffdcd19

Please sign in to comment.