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

stdbin: adding mkdir #240

Merged
merged 5 commits into from
Oct 7, 2017
Merged

stdbin: adding mkdir #240

merged 5 commits into from
Oct 7, 2017

Conversation

i4ki
Copy link
Collaborator

@i4ki i4ki commented Sep 27, 2017

This PR starts a long road to address #230.

As I'm using a lot of windows nowadays... I'll start scratching my itches, by adding the programs I'm missing in windows. The work for the stdbin build system and integrated tests could come up in another PR.

Another PR could be created to copy our programs from c0defellas/enzo to here also.

p.s.: the name of the branch is add-stdbin-pwd because pwd was my initial target for this development, but soon realized I was unable to create the stdbin directory in windows without right-click in explorer ... Then mkdir priority escalated very fast =P

@codecov-io
Copy link

codecov-io commented Sep 27, 2017

Codecov Report

Merging #240 into master will decrease coverage by 0.1%.
The diff coverage is 23.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #240      +/-   ##
==========================================
- Coverage   57.05%   56.95%   -0.11%     
==========================================
  Files          26       27       +1     
  Lines        4403     4416      +13     
==========================================
+ Hits         2512     2515       +3     
- Misses       1651     1660       +9     
- Partials      240      241       +1
Impacted Files Coverage Δ
stdbin/mkdir/main.go 23.07% <23.07%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6779f6a...e8d96ad. Read the comment docs.

@@ -7,8 +7,9 @@ buildargs = -ldflags "-X main.VersionString=$(version)" -v
all: build test install

build:
go build $(buildargs) -o ./cmd/nash/nash ./cmd/nash
go build $(buildargs) -o ./cmd/nashfmt/nashfmt ./cmd/nashfmt
cd cmd/nash && go build $(buildargs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this change was needed because on windows the generated binaries must have .exe extensions.

}
err := mkdirs(os.Args[1:])
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

No need to call err.Error

Copy link
Member

@katcipis katcipis left a comment

Choose a reason for hiding this comment

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

LGTM, just small crap because I'm annoying as hell =D


func mkdirs(dirnames []string) error {
for _, d := range dirnames {
if err := os.MkdirAll(d, 0644); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

cant you pass os.ModeDir here instead of 0644 ?

Copy link
Member

Choose a reason for hiding this comment

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

always creating all dirs seems nice, I always do it =).

another thing very common is to ignore if the dir already exists, in the end I always use "-p" for this. What you think about it being the default ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, makes sense. That's what I commonly do also.

Copy link
Collaborator Author

@i4ki i4ki Sep 27, 2017

Choose a reason for hiding this comment

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

cant you pass os.ModeDir here instead of 0644

0644 are the permission bits here, not the file mode. Sorry, did I misunderstand you?

Copy link
Member

Choose a reason for hiding this comment

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

From the name I thought the os.ModeDir would be an integer with the permission bits (indicating the default permissions for directories). My mistake =)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

if s, err := os.Stat(testdir); err != nil {
t.Fatal(err)
} else if s.Mode()&os.ModeDir != os.ModeDir {
t.Errorf("Invalid directory mode: %v", s.Mode())
Copy link
Member

Choose a reason for hiding this comment

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

Why Errorf instead of Fatalf since all other checks results on Fatal ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm idiot =)

Copy link
Member

Choose a reason for hiding this comment

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

auheauheauheuaheauheauhe yeah like no one else does this kind of thing =P

defer os.RemoveAll(tmpDir)
for _, p := range testDirs {
testdir := filepath.FromSlash(path.Join(tmpDir, p))
err = mkdirs([]string{testdir})
Copy link
Member

Choose a reason for hiding this comment

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

Isn't a good idea to test with arrays bigger than one too ? Also, what happens if the array is empty ? (can test it on the function or on the final cmd)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, there are missing test cases. I made this in a rush... =/
thanks

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for working on this =). We can add an TODO too ;-)

@@ -23,6 +24,7 @@ install: build
cp -p ./cmd/nashfmt/nashfmt $(NASHROOT)/bin
rm -rf $(NASHROOT)/stdlib
cp -pr ./stdlib $(NASHROOT)/stdlib
cp -pr ./stdbin/mkdir/mkdir $(NASHROOT)/bin/mkdir
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this install still only works on unix, I wll address this in the windows branch soon.

Copy link
Member

Choose a reason for hiding this comment

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

thanks, I dont even have an env to test this kind of stuff =P (nor the patience)

@i4ki
Copy link
Collaborator Author

i4ki commented Oct 1, 2017

@katcipis Did you take a look at changes made?
I need this code in the fix-windows branch to finish the tests there :)

@i4ki i4ki mentioned this pull request Oct 1, 2017
Copy link
Member

@vitorarins vitorarins left a comment

Choose a reason for hiding this comment

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

LGTM

@i4ki i4ki merged commit 1c51e3d into master Oct 7, 2017
@i4ki i4ki deleted the add-stdbin-pwd branch October 7, 2017 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants