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

os: MkdirAll exits without creating all folders #20289

Closed
AlexRouSg opened this issue May 9, 2017 · 8 comments
Closed

os: MkdirAll exits without creating all folders #20289

AlexRouSg opened this issue May 9, 2017 · 8 comments

Comments

@AlexRouSg
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

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

1.8.1

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build846921896=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

path := "something/with/nested/folders"
if err := os.MkdirAll(path, 0755); err != nil {
	log.Fatalln(err)
}

if err := os.Chdir(path); err != nil {
	log.Fatalln(err)
}

What did you expect to see?

Directory created and changed working directory.

What did you see instead?

abort: error getting current working directory: No such file or directory

Last folder in the path was never created, even sleeping does not create the folder. Only exiting the program does the folder appear in the filesystem.

@ianlancetaylor ianlancetaylor changed the title os.MkdirAll exits without creating all folders os: MkdirAll exits without creating all folders May 9, 2017
@ianlancetaylor
Copy link
Contributor

Please show us a complete, standalone, preferably small, program that demonstrates the problem. Thanks.

@AlexRouSg
Copy link
Contributor Author

Ok this is embarrassing ... for some reason it started working. I didn't even closed my editor/terminals and it just decided to work.

@AlexRouSg
Copy link
Contributor Author

This is seriously weird. If I just have the mkdirall and the chdir commands it works. But if it's with the rest of the file it doesn't?

package main

import (
	"log"
	"os"
	"os/exec"
	"strings"
	"runtime"
)

const SDL_VR = "2.0.5"

func run(file string, args ...string) {
	cmd := exec.Command(file, args...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Env = os.Environ()
	//cmd.Env = append(cmd.Env, "CC=musl-gcc")

	err := cmd.Run()

	if err != nil {
		os.Exit(1)
	}
}

func main() {
	path := os.Args[1] + "Build/SDL"

	if err := os.MkdirAll(path, 0755); err != nil {
		log.Fatalln(err)
	}

	if err := os.Chdir(path); err != nil {
		log.Fatalln(err)
	}

	if _, err := os.Stat(path); err == nil {
		out, err := exec.Command("hg", "id").Output()

		if err == nil {
			tag := strings.Fields(string(out))[1]

			if tag == "release-"+SDL_VR+"/tip" {
				if err := os.Chdir(path); err != nil {
					log.Fatalln(err)
				}

				run("sh", "-c", path+"/configure --disable-shared --prefix="+path)
				run("sh", "-c", "make -j " + string(runtime.NumCPU()))
				run("sh", "-c", "make install")
				os.Exit(0)
			}
		}

		os.RemoveAll(path)
	}

	run("hg", "clone", "http://hg.libsdl.org/SDL#release-"+SDL_VR)
	run("hg", "tag", "-l", "release-"+SDL_VR)
	run("sh", "-c", path+"/configure --disable-shared --prefix="+path)
	run("sh", "-c", "make -j " + string(runtime.NumCPU()))
	run("sh", "-c", "make install")
}

@AlexRouSg AlexRouSg reopened this May 9, 2017
@AlexRouSg
Copy link
Contributor Author

If I comment out the os.RemoveAll(path) it works??

@mattn
Copy link
Member

mattn commented May 9, 2017

Please make sure what happen with your code. please check all of err returned.

@AlexRouSg
Copy link
Contributor Author

There is no error from os.MkdirAll and os.Chdir only says "abort: error getting current working directory: No such file or directory"

@mattn
Copy link
Member

mattn commented May 9, 2017

This seems not be a bug of Go. Please check output of commands you run.

@AlexRouSg
Copy link
Contributor Author

OK my bad, thought the output was coming from os.Chdir lol
Was actually one of the commands I'm running

@golang golang locked and limited conversation to collaborators May 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants