forked from djui/await
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.go
More file actions
37 lines (31 loc) · 632 Bytes
/
file.go
File metadata and controls
37 lines (31 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"context"
"errors"
"net/url"
"os"
"path/filepath"
)
type fileResource struct {
url.URL
}
func (r *fileResource) Await(context.Context) error {
// Unify absolute and relative file paths
filePath := filepath.Join(r.URL.Host, r.URL.Path)
opts := parseFragment(r.URL.Fragment)
_, err := os.Stat(filePath)
if _, ok := opts["absent"]; ok {
if err == nil {
return &unavailabilityError{errors.New("file exists")}
} else if os.IsNotExist(err) {
return nil
}
} else {
if err == nil {
return nil
} else if os.IsNotExist(err) {
return &unavailabilityError{err}
}
}
return err
}