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

x/mobile : os.Create and os.Open not working as expected #19219

Closed
mintyowl opened this issue Feb 21, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@mintyowl
Copy link

commented Feb 21, 2017

What version of Go are you using (go version)?

1.7.5

What operating system and processor architecture are you using (go env)?

Windows 10 64 bit

Android SDK 23, Lollipop (For React Native)

Android NDK 13.1

What did you do?

package component

import (
	"encoding/json"
	"io/ioutil"
	"os"
)


type LastComponent struct {
	Name string
}

const fname = "componentfiles"


func Persist(comp string) string {
	lcomp := LastComponent{Name: comp}
	b, err := json.Marshal(lcomp)
	if err != nil {
		return "err-MARSHAL"
	}
	file, err := os.Create(fname)
	if err != nil {
		return "err-CREATE-FILE"
	}
	defer file.Close()
	_, err = file.Write(b)
	if err != nil {
		return "err-FILE-WRITE-PROB"
	}
	return ""
}

func Component() string {
	f, err := os.Open(fname)
	if err != nil {
		return "err-FILE-NOT-OPEN"
	}
	defer f.Close()
	b, err := ioutil.ReadAll(f)
	if err != nil {
		return ""
	}
	var v LastComponent
	json.Unmarshal(b, &v)
	return v.Name
}


}

The code above works fine and so does the javascript side of code. I keep receiving err-CREATE-FILE inside my javascript. So os.Create and os.Open are not working as expected.

Even though it is an internal storage and permissions are not required, but I just turned them on anyways in manifest file, but with no avail.

What did you expect to see?

os.Create and os.Open should successfully create and open file resp.

What did you see instead?

Tried even on actual device with debug on, but I keep getting err-CREATE-FILE inside my javascript (React Native). So os.Create and os.Open are not working as expected.

@mintyowl

This comment has been minimized.

Copy link
Author

commented Feb 21, 2017

In adb logcat, i get this all over the place

E/Vold ( 276): Failed to find mounted volume for /storage/sdcard1/Android/data/com.gotest/cache/

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Feb 21, 2017

@mintyowl I don't see how someone can help you here. I tried reproducing your "bug", but I cannot, because you did not answered "What did you do?" question. You did not provided any steps for me to follow. Please try again. Thank you.

Alex

@mintyowl

This comment has been minimized.

Copy link
Author

commented Feb 22, 2017

I dont know what problem there is. I could not solve it and I am closing it for now.

@mintyowl mintyowl closed this Feb 22, 2017

@golang golang locked and limited conversation to collaborators Feb 22, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.