Open [re]opens the given filename, looking on standard BIBINPUTS or TEXINPUTS env var paths if not found locally. If Mod >= mod timestamp on the file, and BibTex is already loaded, then nothing happens (already have it), but otherwise it parses the file and puts contents in BibTex field.
(fname string)
| 65 | // and BibTex is already loaded, then nothing happens (already have it), but |
| 66 | // otherwise it parses the file and puts contents in BibTex field. |
| 67 | func (fl *File) Open(fname string) error { |
| 68 | path := fname |
| 69 | var err error |
| 70 | if fl.File == "" { |
| 71 | path, err = FullPath(fname) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | fl.File = path |
| 76 | fl.BibTex = nil |
| 77 | fl.Mod = time.Time{} |
| 78 | // fmt.Printf("first open file: %s path: %s\n", fname, fl.File) |
| 79 | } |
| 80 | st, err := os.Stat(fl.File) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | if fl.BibTex != nil && !fl.Mod.Before(st.ModTime()) { |
| 85 | // fmt.Printf("existing file: %v is fine: file mod: %v last mod: %v\n", fl.File, st.ModTime(), fl.Mod) |
| 86 | return nil |
| 87 | } |
| 88 | f, err := os.Open(fl.File) |
| 89 | if err != nil { |
| 90 | return err |
| 91 | } |
| 92 | defer f.Close() |
| 93 | parsed, err := Parse(f) |
| 94 | if err != nil { |
| 95 | err = fmt.Errorf("Bibtex bibliography: %s not loaded due to error(s):\n%v", fl.File, err) |
| 96 | return err |
| 97 | } |
| 98 | fl.BibTex = parsed |
| 99 | fl.Mod = st.ModTime() |
| 100 | // fmt.Printf("(re)loaded bibtex bibliography: %s\n", fl.File) |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | ////////////////////////////////////////////////////////////////////// |
| 105 | // Files |