Commit Graph

21 Commits

Author SHA1 Message Date
DenKoren 8292c09038 fix: do not clean bpath when it is empty to not root into '.' 2024-03-25 07:58:26 +01:00
DenKoren 08d1d4a126 allow absolute paths in BasePathFs when prefix is "" on windows 2024-03-25 07:48:41 +01:00
Bjørn Erik Pedersen cf95922e71 all: Run gofumpt -l -w . 2023-02-23 10:17:14 +01:00
Bjørn Erik Pedersen c92ae364de Make IOFS.ReadDir check for fs.ReadDirFile
And implement `fs.ReadDirFile` for `BasePathFile`.

There are other `File` implementations that could also benefit from the above, but
this is a start.

The primary motivation behind this is to allow `fs.WalkDir` use the native
implementation whenever possible, as that new function was added in Go 1.16 with
speed as its main selling point.

This commit also adds a benchmark for `fs.WalkDir` that, when compared to the main branch:

```bash
name        old time/op    new time/op    delta
WalkDir-10     369µs ± 1%     196µs ± 3%  -46.89%  (p=0.029 n=4+4)

name        old alloc/op   new alloc/op   delta
WalkDir-10    85.3kB ± 0%    40.2kB ± 0%  -52.87%  (p=0.029 n=4+4)

name        old allocs/op  new allocs/op  delta
WalkDir-10       826 ± 0%       584 ± 0%  -29.30%  (p=0.029 n=4+4)
```

Fixes #365
2022-07-14 15:11:09 +02:00
Mike Futerko cb1d580bf4 Fix Chown() pull request errors 2020-12-07 15:19:45 +02:00
Scott Owens b4b149f834 adding support for Linker and LinkReader 2020-05-20 23:00:47 +10:00
Bohdan Lisovskyi 30c3c32863 add chown method 2020-01-22 16:25:31 +02:00
Bjørn Erik Pedersen 63644898a8
Return os.ErrNotExist in BasePathFs on abs URLs on Windows
So it can be used in a composite filesystem.

Fixes #162
2018-04-01 22:57:52 +02:00
Bjørn Erik Pedersen 8902da1e4d
Add an optional Lstater interface
The interface has one method returning the `FileInfo` and a flag telling if `Lstat` was called or not.

```go
type Lstater interface {
    LstatIfPossible(name string) (os.FileInfo, bool, error)
}
```

`Lstat` is currently only supported by the `OsFs`, but since that `Fs` can be used in others, they will also support it by proxy.

But not always, so hence this optional interface.

The interface is in this commit implemented for:

* BasePathFs
* OsFs
* CopyOnWriteFs
* ReadOnlyFs

Fixes #75
2018-04-01 22:57:51 +02:00
Albert Z Wang c5621b3590 clean basepath before stripping 2017-11-29 13:56:26 -05:00
Albert Z Wang 9034a12a59 add BasePathFile to fix File.Name() on BasePathFS 2017-11-29 00:20:21 -05:00
Sotirios Mantziaris 72b3142684 Eliminate go vet warnings 2017-01-09 23:53:20 +01:00
Francois Hill (home win10) 7b5e657cdb Revert the previous `fullPath` changes and add tests for "nested" `BasePath`'s 2016-04-20 03:23:58 +02:00
Francois Hill (dell laptop) 139c7715f0 Closes spf13/afero#79
Rather keep the `RealPath` behaviour as originally implemented. Added a new method `fullPath` which is used by all other methods like `MkDir`.
2016-04-18 20:14:10 +02:00
Francois Hill (dell laptop) 9a1fcfb267 Closes spf13/afero#79
Added fix to support "nested" `BasePathFs`. Unit-tests are also included.
2016-04-18 19:29:19 +02:00
bep ddb4d0857d Improve absolute file paths handling in BasePathFs
A common mistake in using the BasePathFs is to give it a real
OS absolute file path instead of a virtual one relative to the virtual base.

This commit adds some tests and returns an error on Windows in this case.

On Unix we have to train the users to do a better job.

See https://github.com/spf13/hugo/issues/1800
2016-02-15 19:09:17 +01:00
Steve Francia 220647edb9 Permit accessing basePath root in BasePathFs (with test) 2016-01-12 00:34:15 -05:00
Steve Francia fe8e895336 Migrate all backends & readme to use constructorish New... 2016-01-11 21:41:03 -05:00
Steve Francia a3ed628486 refine BasePathFs implementation 2016-01-11 20:48:25 -05:00
Steve Francia da00b1fb7c port BasePathFs from filter to filesystem 2016-01-11 20:48:25 -05:00
Hanno Hecker 205066d391 Add BasePathFs as FilterFs
* add a BasePathFs implemented as FilterFs:
  The BasePathFs restricts all operations to a given path within an Fs.
  The given file name to the operations on this Fs will be prepended
  with the base path before calling the base Fs.
  Any file name (after filepath.Clean()) outside this base path will be
  treated as non existing file.

* fix meaning of "facere" - "facio" means "I do", "facere" is the base
  form
2016-01-11 13:21:51 -05:00