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 frontend/app/view/preview/directorypreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ const TableRow = React.forwardRef(function ({
idx,
handleFileContextMenu,
}: TableRowProps) {
const dirPath = useAtomValue(model.normFilePath);
const dirPath = useAtomValue(model.statFilePath);
const connection = useAtomValue(model.connection);

const dragItem: DraggedFile = {
Expand Down
53 changes: 5 additions & 48 deletions frontend/app/view/preview/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ import { TabRpcClient } from "@/app/store/wshrpcutil";
import { BlockHeaderSuggestionControl } from "@/app/suggestion/suggestion";
import { CodeEditor } from "@/app/view/codeeditor/codeeditor";
import { Markdown } from "@/element/markdown";
import {
atoms,
getConnStatusAtom,
getOverrideConfigAtom,
getSettingsKeyAtom,
globalStore,
refocusNode,
} from "@/store/global";
import { getConnStatusAtom, getOverrideConfigAtom, getSettingsKeyAtom, globalStore, refocusNode } from "@/store/global";
import * as services from "@/store/services";
import * as WOS from "@/store/wos";
import { getWebServerEndpoint } from "@/util/endpoints";
Expand Down Expand Up @@ -141,8 +134,6 @@ export class PreviewModel implements ViewModel {

metaFilePath: Atom<string>;
statFilePath: Atom<Promise<string>>;
normFilePath: Atom<Promise<string>>;
loadableStatFilePath: Atom<Loadable<string>>;
loadableFileInfo: Atom<Loadable<FileInfo>>;
connection: Atom<Promise<string>>;
connectionImmediate: Atom<string>;
Expand Down Expand Up @@ -341,7 +332,6 @@ export class PreviewModel implements ViewModel {
const isCeView = loadableSV.state == "hasData" && loadableSV.data.specializedView == "codeedit";
if (mimeType == "directory") {
const showHiddenFiles = get(this.showHiddenFiles);
const settings = get(atoms.settingsAtom);
return [
{
elemtype: "iconbutton",
Expand Down Expand Up @@ -379,11 +369,6 @@ export class PreviewModel implements ViewModel {
const fileInfo = await get(this.statFile);
return fileInfo?.path;
});
this.normFilePath = atom<Promise<string>>(async (get) => {
const fileInfo = await get(this.statFile);
return fileInfo?.path;
});
this.loadableStatFilePath = loadable(this.statFilePath);
this.connection = atom<Promise<string>>(async (get) => {
const connName = get(this.blockAtom)?.meta?.connection;
try {
Expand All @@ -399,7 +384,6 @@ export class PreviewModel implements ViewModel {
});
this.statFile = atom<Promise<FileInfo>>(async (get) => {
const fileName = get(this.metaFilePath);
console.log("stat file", fileName);
const path = await this.formatRemoteUri(fileName, get);
if (fileName == null) {
return null;
Expand Down Expand Up @@ -492,17 +476,13 @@ export class PreviewModel implements ViewModel {
async getSpecializedView(getFn: Getter): Promise<{ specializedView?: string; errorStr?: string }> {
const mimeType = await getFn(this.fileMimeType);
const fileInfo = await getFn(this.statFile);
const fileName = await getFn(this.statFilePath);
const fileName = fileInfo?.name;
const connErr = getFn(this.connectionError);
const editMode = getFn(this.editMode);
const parentFileInfo = await this.getParentInfo(fileInfo);

if (connErr != "") {
return { errorStr: `Connection Error: ${connErr}` };
}
if (parentFileInfo?.notfound ?? false) {
return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` };
}
if (fileInfo?.notfound) {
return { specializedView: "codeedit" };
}
Expand Down Expand Up @@ -585,19 +565,6 @@ export class PreviewModel implements ViewModel {
globalStore.set(this.newFileContent, null);
}

async getParentInfo(fileInfo: FileInfo): Promise<FileInfo | undefined> {
try {
const parentFileInfo = await RpcApi.FileInfoCommand(TabRpcClient, {
info: {
path: await this.formatRemoteUri(fileInfo.dir, globalStore.get),
},
});
return parentFileInfo;
} catch {
return undefined;
}
}

async goParentDirectory({ fileInfo = null }: { fileInfo?: FileInfo | null }) {
// optional parameter needed for recursive case
const defaultFileInfo = await globalStore.get(this.statFile);
Expand All @@ -609,18 +576,8 @@ export class PreviewModel implements ViewModel {
return true;
}
try {
const newFileInfo = await RpcApi.FileInfoCommand(TabRpcClient, {
info: {
path: await this.formatRemoteUri(fileInfo.dir, globalStore.get),
},
});
if (newFileInfo.path != "" && newFileInfo.notfound) {
console.log("parent does not exist, ", newFileInfo.path);
this.goParentDirectory({ fileInfo: newFileInfo });
return;
}
this.updateOpenFileModalAndError(false);
await this.goHistory(newFileInfo.path);
await this.goHistory(fileInfo.dir);
refocusNode(this.blockId);
} catch (e) {
globalStore.set(this.openFileError, e.message);
Expand Down Expand Up @@ -725,7 +682,7 @@ export class PreviewModel implements ViewModel {
label: "Copy Full Path",
click: () =>
fireAndForget(async () => {
const filePath = await globalStore.get(this.normFilePath);
const filePath = await globalStore.get(this.statFilePath);
if (filePath == null) {
return;
}
Expand Down Expand Up @@ -949,8 +906,8 @@ function StreamingPreview({ model }: SpecializedViewProps) {
function CodeEditPreview({ model }: SpecializedViewProps) {
const fileContent = useAtomValue(model.fileContent);
const setNewFileContent = useSetAtom(model.newFileContent);
const fileName = useAtomValue(model.statFilePath);
const fileInfo = useAtomValue(model.statFile);
const fileName = fileInfo?.name;
const blockMeta = useAtomValue(model.blockAtom)?.meta;

function codeEditKeyDownHandler(e: WaveKeyboardEvent): boolean {
Expand Down
1 change: 0 additions & 1 deletion pkg/remote/awsconn/awsconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func GetConfig(ctx context.Context, profile string) (*aws.Config, error) {
return nil, fmt.Errorf("invalid connection string: %s)", profile)
}
profile = connMatch[1]
log.Printf("GetConfig: profile=%s", profile)

// TODO: Reimplement generic profile support
// profiles, cerrs := wconfig.ReadWaveHomeConfigFile(wconfig.ProfilesFile)
Expand Down
13 changes: 13 additions & 0 deletions pkg/remote/fileshare/fileshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func Read(ctx context.Context, data wshrpc.FileData) (*wshrpc.FileData, error) {
}

func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData] {
log.Printf("ReadStream: %v", data.Info.Path)
client, conn := CreateFileShareClient(ctx, data.Info.Path)
if conn == nil || client == nil {
return wshutil.SendErrCh[wshrpc.FileData](fmt.Errorf(ErrorParsingConnection, data.Info.Path))
Expand All @@ -64,6 +65,7 @@ func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrE
}

func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData) <-chan wshrpc.RespOrErrorUnion[iochantypes.Packet] {
log.Printf("ReadTarStream: %v", data.Path)
client, conn := CreateFileShareClient(ctx, data.Path)
if conn == nil || client == nil {
return wshutil.SendErrCh[iochantypes.Packet](fmt.Errorf(ErrorParsingConnection, data.Path))
Expand All @@ -72,6 +74,7 @@ func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData)
}

func ListEntries(ctx context.Context, path string, opts *wshrpc.FileListOpts) ([]*wshrpc.FileInfo, error) {
log.Printf("ListEntries: %v", path)
client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil {
return nil, fmt.Errorf(ErrorParsingConnection, path)
Expand All @@ -80,6 +83,7 @@ func ListEntries(ctx context.Context, path string, opts *wshrpc.FileListOpts) ([
}

func ListEntriesStream(ctx context.Context, path string, opts *wshrpc.FileListOpts) <-chan wshrpc.RespOrErrorUnion[wshrpc.CommandRemoteListEntriesRtnData] {
log.Printf("ListEntriesStream: %v", path)
client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil {
return wshutil.SendErrCh[wshrpc.CommandRemoteListEntriesRtnData](fmt.Errorf(ErrorParsingConnection, path))
Expand All @@ -88,6 +92,7 @@ func ListEntriesStream(ctx context.Context, path string, opts *wshrpc.FileListOp
}

func Stat(ctx context.Context, path string) (*wshrpc.FileInfo, error) {
log.Printf("Stat: %v", path)
client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil {
return nil, fmt.Errorf(ErrorParsingConnection, path)
Expand All @@ -96,6 +101,7 @@ func Stat(ctx context.Context, path string) (*wshrpc.FileInfo, error) {
}

func PutFile(ctx context.Context, data wshrpc.FileData) error {
log.Printf("PutFile: %v", data.Info.Path)
client, conn := CreateFileShareClient(ctx, data.Info.Path)
if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, data.Info.Path)
Expand All @@ -104,6 +110,7 @@ func PutFile(ctx context.Context, data wshrpc.FileData) error {
}

func Mkdir(ctx context.Context, path string) error {
log.Printf("Mkdir: %v", path)
client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, path)
Expand All @@ -112,6 +119,7 @@ func Mkdir(ctx context.Context, path string) error {
}

func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error {
log.Printf("Move: %v", data)
srcClient, srcConn := CreateFileShareClient(ctx, data.SrcUri)
if srcConn == nil || srcClient == nil {
return fmt.Errorf("error creating fileshare client, could not parse source connection %s", data.SrcUri)
Expand Down Expand Up @@ -140,6 +148,7 @@ func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error {
}

func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error {
log.Printf("Copy: %v", data)
srcClient, srcConn := CreateFileShareClient(ctx, data.SrcUri)
if srcConn == nil || srcClient == nil {
return fmt.Errorf("error creating fileshare client, could not parse source connection %s", data.SrcUri)
Expand All @@ -156,6 +165,7 @@ func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error {
}

func Delete(ctx context.Context, data wshrpc.CommandDeleteFileData) error {
log.Printf("Delete: %v", data)
client, conn := CreateFileShareClient(ctx, data.Path)
if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, data.Path)
Expand All @@ -164,6 +174,7 @@ func Delete(ctx context.Context, data wshrpc.CommandDeleteFileData) error {
}

func Join(ctx context.Context, path string, parts ...string) (*wshrpc.FileInfo, error) {
log.Printf("Join: %v", path)
client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil {
return nil, fmt.Errorf(ErrorParsingConnection, path)
Expand All @@ -172,6 +183,7 @@ func Join(ctx context.Context, path string, parts ...string) (*wshrpc.FileInfo,
}

func Append(ctx context.Context, data wshrpc.FileData) error {
log.Printf("Append: %v", data.Info.Path)
client, conn := CreateFileShareClient(ctx, data.Info.Path)
if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, data.Info.Path)
Expand All @@ -180,6 +192,7 @@ func Append(ctx context.Context, data wshrpc.FileData) error {
}

func GetCapability(ctx context.Context, path string) (wshrpc.FileShareCapability, error) {
log.Printf("GetCapability: %v", path)
client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil {
return wshrpc.FileShareCapability{}, fmt.Errorf(ErrorParsingConnection, path)
Expand Down
8 changes: 0 additions & 8 deletions pkg/remote/fileshare/s3fs/s3fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (c S3Client) Read(ctx context.Context, conn *connparse.Connection, data wsh
func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, data wshrpc.FileData) <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData] {
bucket := conn.Host
objectKey := conn.Path
log.Printf("s3fs.ReadStream: %v", conn.GetFullURI())
rtn := make(chan wshrpc.RespOrErrorUnion[wshrpc.FileData], 16)
go func() {
defer close(rtn)
Expand Down Expand Up @@ -89,7 +88,6 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da
Range: aws.String(fmt.Sprintf("bytes=%d-%d", data.At.Offset, data.At.Offset+int64(data.At.Size)-1)),
})
} else {
log.Printf("reading %v", conn.GetFullURI())
result, err = c.client.GetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(objectKey),
Expand Down Expand Up @@ -117,7 +115,6 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da
Dir: fsutil.GetParentPath(conn),
}
fileutil.AddMimeTypeToFileInfo(finfo.Path, finfo)
log.Printf("file info: %v", finfo)
rtn <- wshrpc.RespOrErrorUnion[wshrpc.FileData]{Response: wshrpc.FileData{Info: finfo}}
if size == 0 {
log.Printf("no data to read")
Expand All @@ -126,10 +123,8 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da
defer utilfn.GracefulClose(result.Body, "s3fs", conn.GetFullURI())
bytesRemaining := size
for {
log.Printf("bytes remaining: %d", bytesRemaining)
select {
case <-ctx.Done():
log.Printf("context done")
rtn <- wshutil.RespErr[wshrpc.FileData](context.Cause(ctx))
return
default:
Expand All @@ -139,7 +134,6 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da
rtn <- wshutil.RespErr[wshrpc.FileData](err)
return
}
log.Printf("read %d bytes", n)
if n == 0 {
break
}
Expand Down Expand Up @@ -488,7 +482,6 @@ func (c S3Client) ListEntriesStream(ctx context.Context, conn *connparse.Connect
}

func (c S3Client) Stat(ctx context.Context, conn *connparse.Connection) (*wshrpc.FileInfo, error) {
log.Printf("Stat: %v", conn.GetFullURI())
bucketName := conn.Host
objectKey := conn.Path
if bucketName == "" || bucketName == fspath.Separator {
Expand Down Expand Up @@ -604,7 +597,6 @@ func (c S3Client) Stat(ctx context.Context, conn *connparse.Connection) (*wshrpc
}

func (c S3Client) PutFile(ctx context.Context, conn *connparse.Connection, data wshrpc.FileData) error {
log.Printf("PutFile: %v", conn.GetFullURI())
if data.At != nil {
log.Printf("PutFile: offset %d and size %d", data.At.Offset, data.At.Size)
return errors.Join(errors.ErrUnsupported, fmt.Errorf("file data offset and size not supported"))
Expand Down
10 changes: 0 additions & 10 deletions pkg/wshrpc/wshremote/wshremote.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ func (impl *ServerImpl) remoteStreamFileDir(ctx context.Context, path string, by
innerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt, false)
fileInfoArr = append(fileInfoArr, innerFileInfo)
if len(fileInfoArr) >= wshrpc.DirChunkSize {
logPrintfDev("sending %d entries\n", len(fileInfoArr))
dataCallback(fileInfoArr, nil, byteRange)
fileInfoArr = nil
}
}
if len(fileInfoArr) > 0 {
logPrintfDev("sending %d entries\n", len(fileInfoArr))
dataCallback(fileInfoArr, nil, byteRange)
}
return nil
Expand Down Expand Up @@ -701,7 +699,6 @@ func (impl *ServerImpl) RemoteFileTouchCommand(ctx context.Context, path string)
}

func (impl *ServerImpl) RemoteFileMoveCommand(ctx context.Context, data wshrpc.CommandFileCopyData) error {
logPrintfDev("RemoteFileCopyCommand: src=%s, dest=%s\n", data.SrcUri, data.DestUri)
opts := data.Opts
destUri := data.DestUri
srcUri := data.SrcUri
Expand Down Expand Up @@ -827,7 +824,6 @@ func (*ServerImpl) RemoteWriteFileCommand(ctx context.Context, data wshrpc.FileD
if err != nil {
return fmt.Errorf("cannot write to file %q: %w", path, err)
}
logPrintfDev("wrote %d bytes to file %q at offset %d\n", n, path, atOffset)
return nil
}

Expand Down Expand Up @@ -872,9 +868,3 @@ func (*ServerImpl) DisposeSuggestionsCommand(ctx context.Context, widgetId strin
suggestion.DisposeSuggestions(ctx, widgetId)
return nil
}

func logPrintfDev(format string, args ...interface{}) {
if wavebase.IsDevMode() {
log.Printf(format, args...)
}
}
Loading