Unify import name used for path

This commit is contained in:
Ming Ming 2022-01-31 17:47:37 +08:00
parent 73980ddf3f
commit 64b1d92927
15 changed files with 44 additions and 43 deletions

View file

@ -16,7 +16,7 @@ import 'package:nc_photos/use_case/find_file.dart';
import 'package:nc_photos/use_case/list_share_with_me.dart';
import 'package:nc_photos/use_case/ls.dart';
import 'package:nc_photos/use_case/ls_single_file.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
abstract class ListSharingItem {
const ListSharingItem(this.share);
@ -317,7 +317,7 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
}
}
// include shared albums
if (path.dirname(webdavPath) ==
if (path_lib.dirname(webdavPath) ==
remote_storage_util.getRemoteAlbumsDir(ev.account)) {
try {
final file = sharedAlbumFiles
@ -369,7 +369,7 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
final futures = shares.map((s) async {
final webdavPath = file_util.unstripPath(ev.account, s.path);
// include pending shared albums
if (path.dirname(webdavPath) ==
if (path_lib.dirname(webdavPath) ==
remote_storage_util.getRemotePendingSharedAlbumsDir(ev.account)) {
try {
final file = pendingSharedAlbumFiles
@ -384,7 +384,7 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
}
}
// include shared albums
if (path.dirname(webdavPath) ==
if (path_lib.dirname(webdavPath) ==
remote_storage_util.getRemoteAlbumsDir(ev.account)) {
try {
final file = sharedAlbumFiles

View file

@ -4,7 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
import 'package:nc_photos/string_extension.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
class LogCapturer {
factory LogCapturer() {
@ -47,13 +47,13 @@ String logFilename(String? filename) {
return "$filename";
}
try {
final basename = path.basenameWithoutExtension(filename);
final basename = path_lib.basenameWithoutExtension(filename);
final displayName = basename.length <= 6
? basename
: "${basename.slice(0, 3)}***${basename.slice(-3)}";
return "${path.dirname(filename) != "." ? "***/" : ""}"
return "${path_lib.dirname(filename) != "." ? "***/" : ""}"
"$displayName"
"${path.extension(filename)}";
"${path_lib.extension(filename)}";
} catch (_) {
return "***";
}

View file

@ -10,7 +10,7 @@ import 'package:nc_photos/json_util.dart' as json_util;
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/string_extension.dart';
import 'package:nc_photos/type.dart';
import 'package:path/path.dart' as path_util;
import 'package:path/path.dart' as path_lib;
int compareFileDateTimeDescending(File x, File y) {
final tmp = y.bestDateTime.compareTo(x.bestDateTime);
@ -508,7 +508,7 @@ extension FileExtension on File {
return path == "." ? "" : path;
}
String get filename => path_util.basename(path);
String get filename => path_lib.basename(path);
/// Compare the server identity of two Files
///

View file

@ -18,7 +18,7 @@ import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
import 'package:nc_photos/touch_token_manager.dart';
import 'package:nc_photos/use_case/compat/v32.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
import 'package:uuid/uuid.dart';
import 'package:xml/xml.dart';
@ -529,7 +529,7 @@ class FileCachedDataSource implements FileDataSource {
// generate a new random token
final token = const Uuid().v4().replaceAll("-", "");
const tokenManager = TouchTokenManager();
final dir = File(path: path.dirname(f.path));
final dir = File(path: path_lib.dirname(f.path));
await tokenManager.setLocalToken(account, dir, token);
final fileRepo = FileRepo(this);
await tokenManager.setRemoteToken(fileRepo, account, dir, token);

View file

@ -5,7 +5,7 @@ import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
import 'package:nc_photos/string_extension.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
bool isSupportedMime(String mime) => _supportedFormatMimes.contains(mime);
@ -60,11 +60,12 @@ CiString getUserDirName(File file) {
}
String renameConflict(String filename, int conflictCount) {
final temp = "${path.basenameWithoutExtension(filename)} ($conflictCount)";
if (path.extension(filename).isEmpty) {
final temp =
"${path_lib.basenameWithoutExtension(filename)} ($conflictCount)";
if (path_lib.extension(filename).isEmpty) {
return temp;
} else {
return "$temp${path.extension(filename)}";
return "$temp${path_lib.extension(filename)}";
}
}

View file

@ -3,7 +3,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/ci_string.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/string_extension.dart';
import 'package:path/path.dart' as path_util;
import 'package:path/path.dart' as path_lib;
enum ShareType {
user,
@ -154,7 +154,7 @@ class Share with EquatableMixin {
}
extension ShareExtension on Share {
String get filename => path_util.basename(path);
String get filename => path_lib.basename(path);
}
class ShareRepo {

View file

@ -5,7 +5,7 @@ import 'dart:typed_data';
import 'package:logging/logging.dart';
import 'package:nc_photos/mobile/android/self_signed_cert.dart';
import 'package:nc_photos/type.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';
@ -62,11 +62,11 @@ class SelfSignedCertManager {
try {
final info = _CertInfo.fromJson(jsonDecode(await f.readAsString()));
_log.info(
"[_readAllCerts] Found certificate info: ${path.basename(f.path)} for host: ${info.host}");
"[_readAllCerts] Found certificate info: ${path_lib.basename(f.path)} for host: ${info.host}");
products.add(info);
} catch (e, stacktrace) {
_log.severe(
"[_readAllCerts] Failed to read certificate file: ${path.basename(f.path)}",
"[_readAllCerts] Failed to read certificate file: ${path_lib.basename(f.path)}",
e,
stacktrace);
}

View file

@ -3,7 +3,7 @@ import 'dart:typed_data';
import 'package:nc_photos/platform/universal_storage.dart' as itf;
import 'package:nc_photos/string_extension.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
import 'package:path_provider/path_provider.dart';
class UniversalStorage extends itf.UniversalStorage {
@ -56,7 +56,7 @@ class UniversalStorage extends itf.UniversalStorage {
Future<Directory> _openStorageDirForFile(String relativePath) async {
final privateDir = await getApplicationSupportDirectory();
final rootPath = "${privateDir.path}/universal_storage";
final dirPath = path.dirname("$rootPath/${relativePath.trimAny('/')}");
final dirPath = path_lib.dirname("$rootPath/${relativePath.trimAny('/')}");
final storageDir = Directory(dirPath);
if (!await storageDir.exists()) {
await storageDir.create(recursive: true);

View file

@ -3,7 +3,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/use_case/move.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
/// Compatibility helper for v25
class CompatV25 {
@ -26,9 +26,9 @@ class _MigrateAlbumFile {
Future<File> call(Account account, File albumFile) async {
assert(CompatV25.isAlbumFileNeedMigration(albumFile));
final newPath = path.dirname(albumFile.path) +
final newPath = path_lib.dirname(albumFile.path) +
"/" +
path.basenameWithoutExtension(albumFile.path) +
path_lib.basenameWithoutExtension(albumFile.path) +
".nc_album.json";
_log.info(
"[call] Migrate album file from '${albumFile.path}' to '$newPath'");

View file

@ -4,7 +4,7 @@ import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/use_case/create_dir.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
class Copy {
Copy(this.fileRepo);
@ -47,7 +47,7 @@ class Copy {
if (e.response.statusCode == 409 && shouldCreateMissingDir) {
// no dir
_log.info("[call] Auto creating parent dirs");
await CreateDir(fileRepo)(account, path.dirname(to));
await CreateDir(fileRepo)(account, path_lib.dirname(to));
await fileRepo.copy(account, file, to,
shouldOverwrite: shouldOverwrite);
} else if (e.response.statusCode == 204 && shouldRenameOnOverwrite) {
@ -74,8 +74,8 @@ class Copy {
return destination;
}
final newName =
file_util.renameConflict(path.basename(destination), retryCount);
return "${path.dirname(destination)}/$newName";
file_util.renameConflict(path_lib.basename(destination), retryCount);
return "${path_lib.dirname(destination)}/$newName";
}
final FileRepo fileRepo;

View file

@ -8,7 +8,7 @@ import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/use_case/create_dir.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
class Move {
Move(this._c) : assert(require(_c));
@ -54,7 +54,7 @@ class Move {
if (e.response.statusCode == 409 && shouldCreateMissingDir) {
// no dir
_log.info("[call] Auto creating parent dirs");
await CreateDir(_c.fileRepo)(account, path.dirname(to));
await CreateDir(_c.fileRepo)(account, path_lib.dirname(to));
await _c.fileRepo
.move(account, file, to, shouldOverwrite: shouldOverwrite);
} else if (e.response.statusCode == 412 && shouldRenameOnOverwrite) {
@ -84,8 +84,8 @@ class Move {
return destination;
}
final newName =
file_util.renameConflict(path.basename(destination), retryCount);
return "${path.dirname(destination)}/$newName";
file_util.renameConflict(path_lib.basename(destination), retryCount);
return "${path_lib.dirname(destination)}/$newName";
}
final DiContainer _c;

View file

@ -11,7 +11,7 @@ import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
class DirPicker extends StatefulWidget {
const DirPicker({
@ -110,7 +110,7 @@ class DirPickerState extends State<DirPicker> {
title: Text(L10n.global().rootPickerNavigateUpItemText),
onTap: () {
try {
_navigateInto(File(path: path.dirname(_currentPath)));
_navigateInto(File(path: path_lib.dirname(_currentPath)));
} catch (e) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),

View file

@ -22,7 +22,7 @@ import 'package:nc_photos/theme.dart';
import 'package:nc_photos/use_case/remove.dart';
import 'package:nc_photos/use_case/remove_share.dart';
import 'package:nc_photos/widget/list_tile_center_leading.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
class SharedFileViewerArguments {
SharedFileViewerArguments(this.account, this.file, this.shares);
@ -84,7 +84,7 @@ class _SharedFileViewerState extends State<SharedFileViewer> {
return CustomScrollView(
slivers: [
SliverAppBar(
title: Text(path.withoutExtension(widget.file.filename)),
title: Text(path_lib.withoutExtension(widget.file.filename)),
pinned: true,
),
if (widget.file.isCollection != true)
@ -268,7 +268,7 @@ class _SharedFileViewerState extends State<SharedFileViewer> {
Future<void> _deleteLinkShareDir() {
// the upper dir is also part of this link share dir
var dirPath = path.dirname(widget.file.path);
var dirPath = path_lib.dirname(widget.file.path);
// make sure we are not accidentally deleting other dirs
if (!dirPath.startsWith(
remote_storage_util.getRemoteLinkSharesDir(widget.account) + "/")) {

View file

@ -33,7 +33,7 @@ import 'package:nc_photos/widget/handler/add_selection_to_album_handler.dart';
import 'package:nc_photos/widget/handler/archive_selection_handler.dart';
import 'package:nc_photos/widget/list_tile_center_leading.dart';
import 'package:nc_photos/widget/photo_date_time_edit_dialog.dart';
import 'package:path/path.dart';
import 'package:path/path.dart' as path_lib;
import 'package:tuple/tuple.dart';
class ViewerDetailPane extends StatefulWidget {
@ -182,7 +182,7 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
color: AppTheme.getSecondaryTextColor(context),
),
),
title: Text(basenameWithoutExtension(widget.file.path)),
title: Text(path_lib.basenameWithoutExtension(widget.file.path)),
subtitle: Text(widget.file.strippedPath),
),
if (!widget.file.isOwned(widget.account.username))

View file

@ -2,7 +2,7 @@ import 'package:bloc_test/bloc_test.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/bloc/ls_dir.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart' as path_lib;
import 'package:test/test.dart';
import '../mock_type.dart';
@ -154,6 +154,6 @@ class _MockFileRepo extends MockFileRepo {
path: "remote.php/dav/files/admin/d1/d2-1/d3",
isCollection: true,
),
].where((element) => path.dirname(element.path) == root.path).toList();
].where((element) => path_lib.dirname(element.path) == root.path).toList();
}
}