Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some Windows issues #283

Merged
merged 3 commits into from
Sep 26, 2019
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
8 changes: 5 additions & 3 deletions acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ func main() {
}()
}

// TODO(fhs): This is not very portable.
// See https://github.com/rjkroege/edwood/issues/222
home = os.Getenv("HOME")
var err error
home, err = os.UserHomeDir()
if err != nil {
log.Fatalf("could not get user home directory: %v", err)
}
acmeshell = os.Getenv("acmeshell")
p := os.Getenv("tabstop")
if p != "" {
Expand Down
11 changes: 9 additions & 2 deletions fsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"io"
"log"
"os"
"os/user"
"sort"
Expand Down Expand Up @@ -275,7 +276,12 @@ func (fs *fileServer) flush(x *Xfid, f *Fid) *Xfid {

func (fs *fileServer) attach(x *Xfid, f *Fid) *Xfid {
if x.fcall.Uname != fs.username {
return fs.respond(x, nil, ErrPermission)
// Ignore mismatch because some libraries gets it wrong
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: get it wrong

// anyway. 9fans.net/go/plan9/client just uses the
// $USER environment variable, which is wrong in Windows
// (See `go doc -u -src 9fans.net/go/plan9/client getuser`)
log.Printf("attach from uname %q does not match %q but allowing anyway",
x.fcall.Uname, fs.username)
}
var id uint64
if x.fcall.Aname != "" {
Expand Down Expand Up @@ -640,7 +646,8 @@ func (dt *DirTab) Dir(id int, user string, clock int64) *plan9.Dir {
func getuser() string {
user, err := user.Current()
if err != nil {
return "Wile E. Coyote"
// Same as https://9fans.github.io/usr/local/plan9/src/lib9/getuser.c
return "none"
}
return user.Username
}
12 changes: 10 additions & 2 deletions fsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,18 @@ func TestFileServerAttach(t *testing.T) {
Type: plan9.Tattach,
Uname: "glenda",
},
f: &Fid{},
}
fs.attach(x, nil)
fs.attach(x, x.f)

want := errorFcall(ErrPermission)
want := &plan9.Fcall{
Type: plan9.Rattach,
Qid: plan9.Qid{
Path: Qdir,
Vers: 0,
Type: plan9.QTDIR,
},
}
if got := mc.ReadFcall(t); !cmp.Equal(got, want) {
t.Fatalf("got response %v; want %v", got, want)
}
Expand Down
8 changes: 6 additions & 2 deletions fsys_windows.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package main

import (
"flag"
"fmt"
"net"

"9fans.net/go/plan9/client"
"github.com/fhs/mux9p"
)

var fsysAddr net.Addr
var (
fsysAddrFlag = flag.String("fsys.addr", "localhost:0", "9P file system listen address")
fsysAddr net.Addr
)

func newPipe() (net.Conn, net.Conn, error) {
c1, c2 := net.Pipe()
return c1, c2, nil
}

func post9pservice(conn net.Conn, name string, mtpt string) error {
l, err := net.Listen("tcp", "localhost:0")
l, err := net.Listen("tcp", *fsysAddrFlag)
if err != nil {
return fmt.Errorf("listen failed: %v", err)
}
Expand Down