FAQ
Hi all,

while looking at os.RemoveAll I came across following code snippet:

  // Otherwise, is this a directory we need to recurse into? dir, serr := Lstat(path) if serr != nil {
   if serr, ok := serr.(*PathError); ok && (IsNotExist(serr.Err) || serr.Err == syscall.ENOTDIR) {
    return nil
   }
   return serr
  }


I wonder why the returned error of Lstat is tested this way. According to
the docs (and the source code of Lstat) errors returned by Lstat are always
of type *PathError.

Regards,

Heiko

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ian Lance Taylor at Jun 22, 2013 at 2:33 pm

    On Sat, Jun 22, 2013 at 6:53 AM, hs wrote:
    while looking at os.RemoveAll I came across following code snippet:

    // Otherwise, is this a directory we need to recurse into?
    dir, serr := Lstat(path)
    if serr != nil {
    if serr, ok := serr.(*PathError); ok && (IsNotExist(serr.Err) || serr.Err
    == syscall.ENOTDIR) {
    return nil
    }
    return serr
    }


    I wonder why the returned error of Lstat is tested this way. According to
    the docs (and the source code of Lstat) errors returned by Lstat are always
    of type *PathError.
    I guess your question: why does the code bother to explicitly verify
    that the error value has type *PathError? Just for future-proofing.
    If os.Lstat changes, or if os.Lstate has a bug, this code won't hide
    it with a program crash doing a failed conversion to *PathError.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • peterGo at Jun 22, 2013 at 8:26 pm
    Heiko,

    Revision: 93c6140bf5e7
    https://code.google.com/p/go/source/detail?r=93c6140bf5e7a71d98923862849d7a19b40a65fe

    Peter
    On Saturday, June 22, 2013 9:53:53 AM UTC-4, hs wrote:

    Hi all,

    while looking at os.RemoveAll I came across following code snippet:

    // Otherwise, is this a directory we need to recurse into? dir, serr := Lstat(path) if serr != nil {
    if serr, ok := serr.(*PathError); ok && (IsNotExist(serr.Err) || serr.Err == syscall.ENOTDIR) {
    return nil
    }
    return serr
    }


    I wonder why the returned error of Lstat is tested this way. According to
    the docs (and the source code of Lstat) errors returned by Lstat are always
    of type *PathError.

    Regards,

    Heiko
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 22, '13 at 1:53p
activeJun 22, '13 at 8:26p
posts3
users3
websitegolang.org

3 users in discussion

Ian Lance Taylor: 1 post Hs: 1 post peterGo: 1 post

People

Translate

site design / logo © 2022 Grokbase