dongyuchen9276
2016-03-17 09:49
浏览 94
已采纳

打开_rels / .rels:权限被拒绝的golang

I was trying to unzip a .docx file. First file of name "[Content_Types].xml" has been extracted. But then I encountered an error as follows:

open frontend/uploads/doc_data/_rels/.rels: permission denied

How can we set permission for this?

The unzip function I use is as follows:

func Unzip(src, dest string) error {
   r, err := zip.OpenReader(src)
   if err != nil {
       return err
   }
   defer r.Close()
   for _, f := range r.File {
       rc, err := f.Open()
       if err != nil {
           return err
       }
       defer rc.Close()
       fpath := filepath.Join(dest, f.Name)
       if f.FileInfo().IsDir() {
           os.MkdirAll(fpath, f.Mode())
       } else {
           var fdir string
           if lastIndex := strings.LastIndex(fpath,string(os.PathSeparator)); lastIndex > -1 {
               fdir = fpath[:lastIndex]
           }
           err = os.MkdirAll(fdir, f.Mode())
           if err != nil {
               log.Fatal(err)
               return err
           }
           f, err := os.OpenFile(
               fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
           if err != nil {
               return err
           }
           defer f.Close()
           _, err = io.Copy(f, rc)
           if err != nil {
               return err
           }
       }
   }
   return nil
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题