Skip to content

Conversation

satotake
Copy link
Contributor

@satotake satotake commented Aug 5, 2018

Summary

Add fileStat method to os
fileStat PATH returns os.FileInfo

Use Case

Method readFile has the size limitation (1MB).
To avoid throwing the error and make a workaround, the size must be got before executing readFile.
Under the current condition, this can be done via []os.FileInfo as a result of readDir.
However, it is a little complicated because you have to handle an array even though you need just a single os.FileInfo.
fileStat is useful in such situations.

@CLAassistant
Copy link

CLAassistant commented Aug 5, 2018

CLA assistant check
All committers have signed the CLA.

tpl/os/os.go Outdated
@@ -130,3 +130,22 @@ func (ns *Namespace) FileExists(i interface{}) (bool, error) {

return status, nil
}

// FileStat Stat returns the os.FileInfo structure describing file.
func (ns *Namespace) FileStat(i interface{}) (_os.FileInfo, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should name it simply os.Stat. I think we (at least has tried) to name the other funcs that more or less wraps the std lib variant with the same name as the original. In this case I think that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see.
I have renamed the name.

tpl/os/init.go Outdated
@@ -55,6 +55,13 @@ func init() {
},
)

ns.AddMethodMapping(ctx.FileStat,
[]string{"fileStat"},
Copy link
Contributor Author

@satotake satotake Aug 5, 2018

Choose a reason for hiding this comment

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

Is it better to rename here?, @bep
In my opinion, fileStat will be better than Stat because we cannot get what kind of stat if Stat is used in Hugo template.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should remove it. We don't need an alias for this, as os.Stat is already short enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah sorry, I did not know we can directly access os like {{ os.Stat "filepath"}} even in Hugo template.
You are right. I have removed it.

In this case, Should I update docs or not?
I mean, is it better to close this or fix it?

@bep bep merged commit 71931b3 into gohugoio:master Aug 6, 2018
@satotake satotake deleted the tpl-os-filestat branch February 29, 2020 07:47
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants