Skip to content

Commit

Permalink
Fix copy subdir win (#137)
Browse files Browse the repository at this point in the history
* FIXED: after delete, only reload cache if needed
* CLEANED-UP: removed useless imports
* FIXED: copy only worked one dir deep under Win, fixes #101
* FIXED: FsWatcher could break after copy operation
* FIXED: download panel could show path with "/" on Windows
  • Loading branch information
warpdesign committed Apr 27, 2020
1 parent db6cbf1 commit 60bf2f0
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 242 deletions.
5 changes: 3 additions & 2 deletions src/components/Downloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import classnames from 'classnames';
import { intentClass } from '@blueprintjs/core/lib/esm/common/classes';
import { AppAlert } from './AppAlert';
import CONFIG from '../config/appConfig'
import { isWin } from '../utils/platform';

const TYPE_ICONS: { [key: string]: IconName } = {
'img': 'media',
Expand Down Expand Up @@ -244,7 +245,7 @@ class DownloadsClass extends React.Component<IProps, IState> {

const intent = this.getIntent(transfer);
const className = intentClass(intent);

const sep = isWin ? '\\' : '/';
const node: ITreeNode =
{
id: transfer.id,
Expand All @@ -265,7 +266,7 @@ class DownloadsClass extends React.Component<IProps, IState> {
node.childNodes.push({
id: id,
icon: file.file.isDir ? 'folder-close' : this.getFileIcon(filetype),
label: file.subDirectory ? (file.subDirectory + '/' + file.file.fullname) : file.file.fullname,
label: file.subDirectory ? (file.subDirectory + sep + file.file.fullname) : file.file.fullname,
secondaryLabel: this.createFileRightLabel(file),
nodeData: {
transfer: file,
Expand Down
5 changes: 1 addition & 4 deletions src/components/SideView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import { Toolbar } from './Toolbar';
import { Statusbar } from './Statusbar';
import { AppState } from "../state/appState";
import { LoginDialog } from "./dialogs/LoginDialog";
import { FileState } from "../state/fileState";
import { Loader } from "./Loader";
import { FileTable } from "./FileTable";
import classnames from 'classnames';
import { DropTargetSpec, DropTargetConnector, DropTargetMonitor, DropTargetCollector, ConnectDropTarget, DropTarget } from "react-dnd";
import { DraggedObject } from './RowRenderer';
import { TabList } from "./TabList";
import { ViewState } from "../state/viewState";
import { AppToaster } from "./AppToaster";
import { Intent } from "@blueprintjs/core";
import { getLocalizedError } from "../locale/error";
import { withNamespaces, WithNamespaces } from "react-i18next";
import { FsLocal, LocalApi } from "../services/plugins/FsLocal";
import { getFS } from "../services/Fs";
import { LocalApi } from "../services/plugins/FsLocal";

interface SideViewProps extends WithNamespaces {
hide: boolean;
Expand Down
9 changes: 6 additions & 3 deletions src/components/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FileMenu } from "./FileMenu";
import { MakedirDialog } from "./dialogs/MakedirDialog";
import { AppAlert } from './AppAlert';
import { Logger } from "./Log";
import { AppToaster, IToasterOpts } from "./AppToaster";
import { AppToaster } from "./AppToaster";
import { withNamespaces, WithNamespaces, Trans } from "react-i18next";
import { WithMenuAccelerators, Accelerators, Accelerator } from "./WithMenuAccelerators";
import { throttle } from "../utils/throttle";
Expand Down Expand Up @@ -206,8 +206,9 @@ export class ToolbarClass extends React.Component<IProps, PathInputState> {
try {
const { viewState } = this.injected;
const fileCache = viewState.getVisibleCache();
const cache = this.cache;

const deleted = await this.cache.delete(this.state.path, fileCache.selected);
const deleted = await cache.delete(this.state.path, fileCache.selected);

// TODO: reset selection ?
if (!deleted) {
Expand All @@ -217,7 +218,9 @@ export class ToolbarClass extends React.Component<IProps, PathInputState> {
// show warning
this.onDeleteError();
}
this.cache.reload();
if (cache.getFS().options.needsRefresh) {
cache.reload();
}
}
} catch (err) {
this.onDeleteError(err);
Expand Down
4 changes: 2 additions & 2 deletions src/services/Fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function MakeId(stats: any): FileID {
}

function isModeExe(mode: number, gid: number, uid: number): Boolean {
if (isWin || mode === -1) {
if (isWin || mode === -1) {
return false;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ export function filetype(mode: number, gid: number, uid: number, extension: stri
export interface FsApi {
// public API
// async methods that may require server access
list(dir: string, transferId?: number): Promise<File[]>;
list(dir: string, watchDir?: boolean, transferId?: number): Promise<File[]>;
cd(path: string, transferId?: number): Promise<string>;
delete(parent: string, files: File[], transferId?: number): Promise<number>;
makedir(parent: string, name: string, transferId?: number): Promise<string>;
Expand Down
8 changes: 4 additions & 4 deletions src/services/plugins/FsGeneric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class GenericApi implements FsApi {
} as File);
}

async list(dir: string, transferId = -1): Promise<File[]> {
async list(dir: string, watchDir = false, transferId = -1): Promise<File[]> {
console.log("FsGeneric.readDirectory");
const pathExists = await this.isDir(dir);

Expand All @@ -97,7 +97,7 @@ class GenericApi implements FsApi {
}
}

off() {}
off() { }

isRoot(path: string): boolean {
return path === "/";
Expand Down Expand Up @@ -129,15 +129,15 @@ class GenericApi implements FsApi {
getParentTree(dir: string): Array<{ dir: string; fullname: string }> {
const numParts = dir.replace(/^\//, "").split("/").length;
const folders = [];
for (let i = 0; i < numParts; ++i) {}
for (let i = 0; i < numParts; ++i) { }
return [];
}

sanityze(path: string) {
return path;
}

on(event: string, cb: (data: any) => void): void {}
on(event: string, cb: (data: any) => void): void { }
}

export const FsGeneric: Fs = {
Expand Down
40 changes: 20 additions & 20 deletions src/services/plugins/FsLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class LocalApi implements FsApi {
loginOptions: ICredentials = null;
onFsChange: (filename: string) => void;

constructor(path: string, onFsChange: (filename: string) => void) {
constructor(_: string, onFsChange: (filename: string) => void) {
this.path = "";
this.onFsChange = onFsChange;
}
Expand Down Expand Up @@ -151,14 +151,14 @@ export class LocalApi implements FsApi {
});
}
})
.catch((err) => {
reject({
code: err.code,
message: err.message,
newName: newName,
oldName: file.fullname
});
})
.catch((err) => {
reject({
code: err.code,
message: err.message,
newName: newName,
oldName: file.fullname
});
})
});
} else {
// reject promise with previous name in case of invalid chars
Expand Down Expand Up @@ -249,7 +249,7 @@ export class LocalApi implements FsApi {
}
}

async list(dir: string, transferId = -1): Promise<File[]> {
async list(dir: string, watchDir = false, transferId = -1): Promise<File[]> {
try {
await this.isDir(dir);
return new Promise<File[]>((resolve, reject) => {
Expand All @@ -258,24 +258,24 @@ export class LocalApi implements FsApi {
reject(err);
} else {
const dirPath = path.resolve(dir);

const files: File[] = [];

for (var i = 0; i < items.length; i++) {
const file = LocalApi.fileFromPath(
path.join(dirPath, items[i])
);
files.push(file);
}
this.onList(dirPath);

watchDir && this.onList(dirPath);

resolve(files);
}
});
});
} catch(err) {
throw({
} catch (err) {
throw ({
code: err.code,
message: `Could not access path: ${dir}`
});
Expand Down Expand Up @@ -310,7 +310,7 @@ export class LocalApi implements FsApi {
ctime: new Date(),
mtime: new Date(),
birthtime: new Date(),
size: stats.size,
size: stats ? stats.size : 0,
isDirectory: () => isDir,
mode: -1,
isSymbolicLink: () => isSymLink,
Expand Down Expand Up @@ -343,7 +343,7 @@ export class LocalApi implements FsApi {
filetype(mode, 0, 0, extension)) ||
"",
isSym: stats.isSymbolicLink(),
target: stats.isSymbolicLink() && name || null,
target: stats.isSymbolicLink() && name || null,
id: MakeId(stats)
};

Expand Down Expand Up @@ -486,7 +486,7 @@ export class LocalApi implements FsApi {
return isWin ? (path.match(/\\$/) ? path : path + "\\") : path;
}

on(event: string, cb: (data: any) => void): void {}
on(event: string, cb: (data: any) => void): void { }
}

export function FolderExists(path: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/plugins/FsSimpleFtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class SimpleFtpApi implements FsApi {
} as File);
}

list(path: string, transferId = -1): Promise<File[]> {
list(path: string, watchDir = false, transferId = -1): Promise<File[]> {
return new Promise(async (resolve, reject) => {
const newpath = this.pathpart(path);

Expand Down
2 changes: 1 addition & 1 deletion src/services/plugins/LocalWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const LocalWatch = {
},
createCallback(path: string) {
// console.log('LocalWatch.createCallback', path);
return debounce((eventType: string, filename: string | Buffer) => {
return debounce((_: string, filename: string) => {
// console.log('changeCallback', eventType, filename);
const callbacks = this.getCallbacks(path);
for (let cb of callbacks) {
Expand Down

0 comments on commit 60bf2f0

Please sign in to comment.