Skip to content

Commit

Permalink
Merge pull request microsoft#94 from Microsoft/remotefs-sync
Browse files Browse the repository at this point in the history
remotefs: Added sync to writes and OpenFile
  • Loading branch information
soccerGB authored Aug 24, 2017
2 parents f87b25d + 2f319d6 commit aa648d4
Show file tree
Hide file tree
Showing 7 changed files with 636 additions and 507 deletions.
8 changes: 2 additions & 6 deletions service/gcsutils/gcstools/remotefs_main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package main

import (
"errors"
"fmt"
"os"

"github.com/Microsoft/opengcs/service/gcsutils/remotefs"
)

// ErrUnknown is returned for an unknown remotefs command
var ErrUnknown = errors.New("unkown command")

func remotefsHandler() error {
if len(os.Args) < 2 {
return ErrUnknown
return remotefs.ErrUnknown
}

command := os.Args[1]
Expand All @@ -33,7 +29,7 @@ func remotefsHandler() error {
for k := range remotefs.Commands {
fmt.Fprintf(os.Stderr, "\t%s\n", k)
}
return ErrUnknown
return remotefs.ErrUnknown
}

func remotefsMain() {
Expand Down
103 changes: 103 additions & 0 deletions service/gcsutils/remotefs/defs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package remotefs

import (
"errors"
"os"
"time"
)

// RemotefsCmd is the name of the remotefs meta command
const RemotefsCmd = "remotefs"

// Name of the commands when called from the cli context (remotefs <CMD> ...)
const (
StatCmd = "stat"
LstatCmd = "lstat"
ReadlinkCmd = "readlink"
MkdirCmd = "mkdir"
MkdirAllCmd = "mkdirall"
RemoveCmd = "remove"
RemoveAllCmd = "removeall"
LinkCmd = "link"
SymlinkCmd = "symlink"
LchmodCmd = "lchmod"
LchownCmd = "lchown"
MknodCmd = "mknod"
MkfifoCmd = "mkfifo"
OpenFileCmd = "openfile"
ReadFileCmd = "readfile"
WriteFileCmd = "writefile"
ReadDirCmd = "readdir"
ResolvePathCmd = "resolvepath"
ExtractArchiveCmd = "extractarchive"
ArchivePathCmd = "archivepath"
)

// ErrInvalid is returned if the parameters are invalid
var ErrInvalid = errors.New("invalid arguments")

// ErrUnknown is returned for an unknown remotefs command
var ErrUnknown = errors.New("unkown command")

// ExportedError is the serialized version of the a Go error.
// It also provides a trivial implementation of the error interface.
type ExportedError struct {
ErrString string
ErrNum int `json:",omitempty"`
}

// Error returns an error string
func (ee *ExportedError) Error() string {
return ee.ErrString
}

// FileInfo is the stat struct returned by the remotefs system. It
// fulfills the os.FileInfo interface.
type FileInfo struct {
NameVar string
SizeVar int64
ModeVar os.FileMode
ModTimeVar int64 // Serialization of time.Time breaks in travis, so use an int
IsDirVar bool
}

var _ os.FileInfo = &FileInfo{}

// Name returns the filename from a FileInfo structure
func (f *FileInfo) Name() string { return f.NameVar }

// Size returns the size from a FileInfo structure
func (f *FileInfo) Size() int64 { return f.SizeVar }

// Mode returns the mode from a FileInfo structure
func (f *FileInfo) Mode() os.FileMode { return f.ModeVar }

// ModTime returns the modification time from a FileInfo structure
func (f *FileInfo) ModTime() time.Time { return time.Unix(0, f.ModTimeVar) }

// IsDir returns the is-directory indicator from a FileInfo structure
func (f *FileInfo) IsDir() bool { return f.IsDirVar }

// Sys provides an interface to a FileInfo structure
func (f *FileInfo) Sys() interface{} { return nil }

// FileHeader is a header for remote *os.File operations for remotefs.OpenFile
type FileHeader struct {
Cmd uint32
Size uint64
}

const (
Read uint32 = iota // Read request command
Write // Write request command
Seek // Seek request command
Close // Close request command
CmdOK // CmdOK is a response meaning request succeeded
CmdFailed // CmdFailed is a response meaning request failed.
)

// SeekHeader is header for the Seek operation for remotefs.OpenFile
type SeekHeader struct {
Offset int64
Whence int32
}
Loading

0 comments on commit aa648d4

Please sign in to comment.