Discussion:
IsReadable , IsWriteable , IsFile & Touch
Oleku Konko
2014-01-20 17:59:27 UTC
Permalink
*Introduction*

Am fairly new to golang and i really appreciate the work that has gone to
the project so far.(Well done guys) I would like to make simple
contributions `os` & `os.FileMode` if it would be permitted

*Case 1 : os.FileMode*

`FileMode.Mode()` already returns the file mode but checking if a file
readable or writable can be simpler rather than parsing the mode


*Case 2 : os*

I would like to add the similar function like unix touch<http://en.wikipedia.org/wiki/Touch_(Unix)>.
This is used to change a file's access, modification timestamps and also
used to create a new empty file if it does not exist.


*Functions / Method *

func Touch(name string) (file *File, err error)

*func *(m FileMode) IsReadable() bool {

*func *(m FileMode) IsWritable() bool {

*func *(m FileMode) IsFile() bool {


*Example *

path , _ := os.Getwd()
location, err := os.Stat(path)

if err != nil {
fmt.Println(err)
}

// Cool but we can make checking more explicit
// Returns drwxrwxrwx - 2147484159
fmt.Printf("%s - %d", location.Mode(),location.Mode())

// Simple check if file is readable
if os.IsReadable() {
// File / Dir Is Readable
}

// Simple check if file is writeable
if os.IsWritable() {
// File / Dir Writable
}

// Preferred Instead of !os.IsDir()
if os.IsFile() {
// X is File
}


// Touch doesn't modify the contents of myfile.txt; it just updates the timestamp
// of the file to the computer's current date and time, whatever that happens to be
// Or, if path does not exist it is created, with zero length.

os.Touch(path) // Touch the file



*Conclusion*

I know this are basic synthetic sugar but it might make it easy for new
developers and i would like to continue in my own little way

*What do you guys think ? *
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Brad Fitzpatrick
2014-01-20 18:02:06 UTC
Permalink
We already have IsFile... it's called IsRegular.

IsReadable and IsWritable wouldn't be reliable enough... the filesystem can
be mounted read-only, or corrupt, or there could be extended attribute ACLs
on the file, etc. The only reliable strategy is to just try to open it for
read or write and see if it fails.
Post by Oleku Konko
*Introduction*
Am fairly new to golang and i really appreciate the work that has gone to
the project so far.(Well done guys) I would like to make simple
contributions `os` & `os.FileMode` if it would be permitted
*Case 1 : os.FileMode*
`FileMode.Mode()` already returns the file mode but checking if a file
readable or writable can be simpler rather than parsing the mode
*Case 2 : os*
I would like to add the similar function like unix touch<http://en.wikipedia.org/wiki/Touch_(Unix)>.
This is used to change a file's access, modification timestamps and also
used to create a new empty file if it does not exist.
*Functions / Method *
func Touch(name string) (file *File, err error)
*func *(m FileMode) IsReadable() bool {
*func *(m FileMode) IsWritable() bool {
*func *(m FileMode) IsFile() bool {
*Example *
path , _ := os.Getwd()
location, err := os.Stat(path)
if err != nil {
fmt.Println(err)
}
// Cool but we can make checking more explicit
// Returns drwxrwxrwx - 2147484159
fmt.Printf("%s - %d", location.Mode(),location.Mode())
// Simple check if file is readable
if os.IsReadable() {
// File / Dir Is Readable
}
// Simple check if file is writeable
if os.IsWritable() {
// File / Dir Writable
}
// Preferred Instead of !os.IsDir()
if os.IsFile() {
// X is File
}
// Touch doesn't modify the contents of myfile.txt; it just updates the timestamp
// of the file to the computer's current date and time, whatever that happens to be
// Or, if path does not exist it is created, with zero length.
os.Touch(path) // Touch the file
*Conclusion*
I know this are basic synthetic sugar but it might make it easy for new
developers and i would like to continue in my own little way
*What do you guys think ? *
--
---
You received this message because you are subscribed to the Google Groups
"golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Oleku Konko
2014-01-21 15:16:20 UTC
Permalink
Thanks for the feedback ... what about *os.Touch* ?
Post by Brad Fitzpatrick
We already have IsFile... it's called IsRegular.
IsReadable and IsWritable wouldn't be reliable enough... the filesystem
can be mounted read-only, or corrupt, or there could be extended attribute
ACLs on the file, etc. The only reliable strategy is to just try to open
it for read or write and see if it fails.
Post by Oleku Konko
*Introduction*
Am fairly new to golang and i really appreciate the work that has gone to
the project so far.(Well done guys) I would like to make simple
contributions `os` & `os.FileMode` if it would be permitted
*Case 1 : os.FileMode*
`FileMode.Mode()` already returns the file mode but checking if a file
readable or writable can be simpler rather than parsing the mode
*Case 2 : os*
I would like to add the similar function like unix touch<http://en.wikipedia.org/wiki/Touch_(Unix)>.
This is used to change a file's access, modification timestamps and also
used to create a new empty file if it does not exist.
*Functions / Method *
func Touch(name string) (file *File, err error)
*func *(m FileMode) IsReadable() bool {
*func *(m FileMode) IsWritable() bool {
*func *(m FileMode) IsFile() bool {
*Example *
path , _ := os.Getwd()
location, err := os.Stat(path)
if err != nil {
fmt.Println(err)
}
// Cool but we can make checking more explicit
// Returns drwxrwxrwx - 2147484159
fmt.Printf("%s - %d", location.Mode(),location.Mode())
// Simple check if file is readable
if os.IsReadable() {
// File / Dir Is Readable
}
// Simple check if file is writeable
if os.IsWritable() {
// File / Dir Writable
}
// Preferred Instead of !os.IsDir()
if os.IsFile() {
// X is File
}
// Touch doesn't modify the contents of myfile.txt; it just updates the timestamp
// of the file to the computer's current date and time, whatever that happens to be
// Or, if path does not exist it is created, with zero length.
os.Touch(path) // Touch the file
*Conclusion*
I know this are basic synthetic sugar but it might make it easy for new
developers and i would like to continue in my own little way
*What do you guys think ? *
--
---
You received this message because you are subscribed to the Google Groups
"golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Brad Fitzpatrick
2014-01-21 17:50:03 UTC
Permalink
That's a four line function that is both easy to implement and doesn't come
up often enough to warrant inclusion.
Post by Oleku Konko
Thanks for the feedback ... what about *os.Touch* ?
Post by Brad Fitzpatrick
We already have IsFile... it's called IsRegular.
IsReadable and IsWritable wouldn't be reliable enough... the filesystem
can be mounted read-only, or corrupt, or there could be extended attribute
ACLs on the file, etc. The only reliable strategy is to just try to open
it for read or write and see if it fails.
Post by Oleku Konko
*Introduction*
Am fairly new to golang and i really appreciate the work that has gone
to the project so far.(Well done guys) I would like to make simple
contributions `os` & `os.FileMode` if it would be permitted
*Case 1 : os.FileMode*
`FileMode.Mode()` already returns the file mode but checking if a file
readable or writable can be simpler rather than parsing the mode
*Case 2 : os*
I would like to add the similar function like unix touch<http://en.wikipedia.org/wiki/Touch_(Unix)>.
This is used to change a file's access, modification timestamps and also
used to create a new empty file if it does not exist.
*Functions / Method *
func Touch(name string) (file *File, err error)
*func *(m FileMode) IsReadable() bool {
*func *(m FileMode) IsWritable() bool {
*func *(m FileMode) IsFile() bool {
*Example *
path , _ := os.Getwd()
location, err := os.Stat(path)
if err != nil {
fmt.Println(err)
}
// Cool but we can make checking more explicit
// Returns drwxrwxrwx - 2147484159
fmt.Printf("%s - %d", location.Mode(),location.Mode())
// Simple check if file is readable
if os.IsReadable() {
// File / Dir Is Readable
}
// Simple check if file is writeable
if os.IsWritable() {
// File / Dir Writable
}
// Preferred Instead of !os.IsDir()
if os.IsFile() {
// X is File
}
// Touch doesn't modify the contents of myfile.txt; it just updates the timestamp
// of the file to the computer's current date and time, whatever that happens to be
// Or, if path does not exist it is created, with zero length.
os.Touch(path) // Touch the file
*Conclusion*
I know this are basic synthetic sugar but it might make it easy for new
developers and i would like to continue in my own little way
*What do you guys think ? *
--
---
You received this message because you are subscribed to the Google
Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/groups/opt_out.
--
---
You received this message because you are subscribed to the Google Groups
"golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...