Commit Graph

65 Commits

Author SHA1 Message Date
Benjamin Sago f8df02dae7 Batch source formatting
I read through every file and applied a couple of rustfmt suggestions. The brace placement and alignment of items on similar lines has been made consistent, even if neither are rustfmt's default style (a file has been put in place to enforce this). Other changes are:

• Alphabetical imports and modules
• Comma placement at the end of match blocks
• Use newlines and indentation judiciously
• Spaces around associated types
• Spaces after negations (it makes it more clear imho)
• Comment formatting
• Use early-returns and Optional `?` where appropriate
2020-10-10 20:02:55 +01:00
Benjamin Sago f0c139ca68 Better referencing
This commit makes changes to the way variables are referenced:

• Make types Copy when possible
• Make methods take `self` instead of `&self` where possible (trivially_copy_pass_by_ref)
• Remove unnecessary borrowing (needless_ref)
• Remove unnecessary cloning (clone_on_copy)
• Remove `ref` from match arms where possible (new Rust match ergonomics)
2020-10-10 15:30:19 +01:00
Benjamin Sago 74d9f1402b Some Clippy fixes 2020-10-10 13:33:50 +01:00
Benjamin Sago 04e2d4c692 Just straight-up roll our own logger
This commit removes the env_logger dependency, replacing it with a simple implementation. Doing so removes like ten other transitive dependencies that no longer need to be included in the build.

It also gains the ability to enable trace-level logging. The users crate, which contains such logging statements as of the version I published a few days ago, has been upgraded to celebrate.

Also, change the log imports to globs. I'm only interested that a file doing logging, not what level it's logging at.
2020-10-10 02:01:12 +01:00
Benjamin Sago d901bb289c
Merge pull request #654 from ariasuni/cleaning
Clean code a bit and fix typos in code documentation
2020-10-08 21:49:20 +01:00
ariasuni dba3f37b0a Fix Clippy lints 2020-05-24 21:43:55 +02:00
Thomas Hurst acb7c49abf Improve handling of unavailable timestamps.
Previously if a timestamp was unavailable, it defaulted to the epoch.
Prior to this it defaulted to a zero duration.

Switch to an Option<SystemTime> and move the handling of unavailable
timestamps to rendering.
2020-05-19 02:31:15 +00:00
Thomas Hurst 86163ab298 Restore ctime handling with correct pre-epoch behaviour 2020-05-18 23:21:56 +00:00
Thomas Hurst bc830b9158 Handle timestamps before UNIX_EPOCH (#658)
Instead of returning a Duration since the epoch from file metadata,
which cannot represent times before it, return the SystemTime directly.

Move conversion closer to where it's needed, and perform it infallibly.
2020-05-18 21:03:44 +00:00
Laurent Arnoud bd655f9c20
Remove unused imports on fs/file.rs 2020-01-19 18:40:34 +01:00
Benjamin Sago 490d9680c2 Merge branch 'fix-handling-maybe-unsupported-time-metadata' of https://github.com/ariasuni/exa into ariasuni-fix-handling-maybe-unsupported-time-metadata
# Conflicts:
#	src/fs/file.rs
#	src/options/filter.rs
#	src/options/view.rs
2020-01-19 16:46:51 +00:00
Benjamin Sago c5a1e8e103
Merge pull request #557 from BrennanMcDonald/master
Added checks for modified/accessed/created metadata
2020-01-19 00:39:40 +00:00
ariasuni a636d08f8b Fix handling of potentially unsupported time metadata
- Checking on a directory doesn’t tell us if supported elsewhere
(some filesystems, like tmpfs, don’t support created time)
- We want to be able to display a column even if some subfiles or
subdirectories don’t support it

So now if unsupported a time of zero is used, and displayed as `-`
2019-12-20 05:37:29 +01:00
Brennan McDonald 215b779d35
Fixed copy-paste bug in access times. 2019-08-03 11:07:16 -07:00
Brennan McDonald f19f7be726
Updated file.rs
Added checks to `file.rs` to ensure that file's metadata exists after `UNIX_EPOCH`.
If the file was accessed/modified/created after UNIX_EPOCH, the current day is displayed.
2019-07-31 15:43:31 -07:00
Bond_009 f599c7ce93 Update to Rust 2018 2019-07-19 20:40:21 +02:00
Benjamin Sago 081bce0479 Merge branch 'fix-warnings-and-rust-2018' of https://github.com/ariasuni/exa into ariasuni-fix-warnings-and-rust-2018
# Conflicts:
#	src/fs/dir.rs
2019-07-15 03:42:33 +01:00
Benjamin Sago faed8f9b82
Merge pull request #457 from ariasuni/fix-sorting-by-created-time
Fix sorting by created time
2019-07-15 03:30:52 +01:00
Benjamin Sago e936d7e09f Prevent infinite loop with -aaR
This happened because exa would recurse into `.` over and over again. There was nothing distinguishing the pseudo-entry for `.` that was being added by `--a` from a `.` passed in on the command-line, so it was looping forever.

It gets fixed by having the File value keep track of whether it’s an --all --all entry, and not recursing into directories with this field set.

Fixes #515
2019-07-13 21:14:42 +01:00
ariasuni 39a49a3d36 Check if the sort field is supported by the OS 2019-03-23 17:23:43 +01:00
ariasuni 56717c7336 Add “changed” sort option, to replace old incorrect “created” 2019-03-23 17:23:40 +01:00
ariasuni b0da0c9055 Use correct metadata for created time 2019-03-23 17:18:18 +01:00
ariasuni 49ed3ed0f8 Fix clippy warnings and explicitely ignore a few, fix future deprecation 2018-12-16 20:50:37 +01:00
Benjamin Sago ecc4138d56 Merge branch 'clippy_fixes' of https://github.com/thibran/exa into thibran-clippy_fixes
# Conflicts:
#	src/options/view.rs
#	src/style/lsc.rs
2018-10-13 22:07:35 +01:00
Thibaut Brandscheid 755876e9b6 fix most clippy warnings 2018-06-19 17:17:39 +02:00
Jesse Luehrs 9bb62fbd63 make exa on symlinks to directories show their contents
right now, `exa foo` and `exa foo/` behave differently, which is
confusing.

fixes https://github.com/ogham/exa/issues/192
2018-03-31 05:00:03 -04:00
Ryan Leung e1a4ed87f2 add #[allow(unused)] for compatibility 2018-02-01 14:52:01 +08:00
Ryan Leung 7fb0347e93 remove unused import 2018-01-31 15:05:20 +08:00
Benjamin Sago 45a807a14f Redo Git implementation to allow --git --recurse
This is all a big commit because it took a lot more work than I thought it would! The commit basically moves Git repositories from being per-directory to living for the whole life of the program. This allows for several directories in the same repository to be listed in the same invocation; before, it would try to rediscover the repository each time! This is why two of the tests “broke”: it suddenly started working with --recurse.

The Dir type does now not use Git at all; because a Dir doesn’t have a Git, then a File doesn’t have one either, so the Git cache gets passed to the render functions which will put them in the Table to render them.
2017-09-01 19:13:47 +01:00
Benjamin Sago 040dbb2414 Use a global Git cache
This commit adds a cache for Git repositories based on the path being queried.

Its only immediate effect is that when you query the same directory twice (such as /testcases/git /testcases/git), it won’t need to check that the second one is a Git directory the second time. So, a minuscule optimisation for something you’d never do anyway? Wrong! It’s going to let us combine multiple entries over the same repository later, letting us use --tree and --recurse, because now Git scanning is behind a factory.
2017-08-28 18:11:38 +01:00
Benjamin Sago d86fc4286b \t and \s+$ 2017-08-26 23:54:12 +01:00
Benjamin Sago 1081762657 Basically, log before doing fs operations 2017-08-19 13:53:33 +01:00
Benjamin Sago 014e179abf One more 2017-08-19 12:22:17 +01:00
Benjamin Sago 6fbb0b8626 More logging things that shouldn’t happen 2017-08-19 11:15:17 +01:00
Benjamin Sago aa5b1867dd Make nanoseconds available to times
The information was always in the Metadata struct; exa just never used it.
2017-07-05 23:08:56 +01:00
Benjamin Sago 5bdf6304bb Fix bug where accessed times were wrong!
It used the mtime, rather than the atime. Copy and paste error. Whoops!
2017-07-05 22:07:03 +01:00
Benjamin Sago 0aa33595d7 Use the optional argument trick 2017-06-29 13:17:26 +01:00
Benjamin Sago 31148eda7b Match up fields with parameter names
The arguments passed to File’s constructor were different from the field names used — these might as well both be the same.

Also, move ext and filename to be File methods to save an import, and add tests.

Also also, by passing a PathBuf in to the constructor directly, we can save one (possibly two) instance/s where we pass in a reference to something we were going to lose ownership of anyway, only to have it basically cloned.
2017-06-29 13:07:45 +01:00
Benjamin Sago 30f74b08b4 Always look up metadata
We can do this because the only File::new invocation that already has metadata is already in the file module, so it doesn’t need its own constructor.
2017-06-29 12:24:04 +01:00
Benjamin Sago dd8bff083f Override the names of . and ..
There was a problem when displaying . and .. in directory listings: their names would normalise to actual names! So instead of literally seeing `.`, you’d see the current directory’s name, inserted in sort order into the list of results. Obviously this is not what we want.

In unrelated news, putting `.` and `..` into the list of paths read from a directory just takes up more heap space for something that’s basically constant.

We can solve both these problems at once by moving the DotFilter to the files iterator in Dir, rather than at the Dir’s creation. Having the iterator know whether it should display `.` and `..` means it can emit those files first, and because it knows what those files really represent, it can override their file names to actually be those sequences of dots.

This is not a perfect solution: the main casualty is that a File can now be constructed with a name, some metadata, both, or neither. This is currently handled with a bunch of Options, and returns IOResult even without doing any IO operations.

But at least all the tests pass!
2017-06-28 18:41:31 +01:00
Benjamin Sago 4295b243e5 Make Dir construction a bit cleaner 2017-06-27 18:13:18 +01:00
Benjamin Sago 20793ce7f4 Implement . and .. by inserting them maually
I originally thought that the entries . and .. were in *every* directory entry, and exa was already doing something to filter it out. And then... I could find no such code! Turns out, if we want those entries present, we have to insert them ourselves.

This was harder than expected. Because the file filter doesn’t have access to the parent directory path, it can’t “filter” the files vector by inserting the files at the beginning.

Instead, we do it at the iterator level. A directory can be scanned in three different ways depending on what sort of dotfiles, if any, are wanted. At this point, we already have access to the parent directory’s path, so we can just insert them manually. The enum got moved to the dir module because it’s used most there.
2017-06-27 01:13:50 +01:00
Benjamin Sago f9f7ad2230 Read setuid/setgid/sticky bits
The problem here was that we were using `metadata.permissions().mode()`, which is capped at 0o777, rather than `metadata.mode()`, which exposes every bit. With this change, we can access the higher-order permission bits, and put them in the Permissions struct.
2017-05-30 15:29:29 +01:00
Benjamin Sago 957c1925b1 PermissionsPlus holds the leftmost column values
The three pieces of information for the leftmost details view column (file type, permissions, and whether xattrs are present) used to be gathered from separate sources and passed around separately before being displayed at the end. Now, file type and permissions are put into a struct, along with the xattrs boolean that’s still getting passed around all over the place but not quite as much.

This was all done because I wanted to be able to test permissions rendering, without having file type and xattrs dragged into the same function.
2017-05-21 10:48:27 +01:00
Benjamin Sago ddd34f3b1f Make DeviceIDs its own type
This is so we can define a render method on it.
2017-05-20 21:55:18 +01:00
Benjamin Sago d82e7b8e5c Some explanatory comments 2017-05-19 09:27:38 +01:00
Benjamin Sago ef5fa90660 Display device IDs when listing devices
Override the size column for block and charater devices, so it shows the major and minor device IDs instead (which are in the Metadata struct somewhere).

This is what ls does when faced with a device.
2017-05-19 09:20:47 +01:00
Benjamin Sago 108a402dbd Re-prefix the paths found by following symlinks
Fixes #134, a bug that showed symlinks incorrectly as broken, but only when the file was listed directly on the command-line *and* the file was in a different directory to the one exa was being run in.

I’m not sure why the old code used `String::new()`, but it doesn’t seem to affect anything.
2017-05-15 22:38:23 +01:00
Benjamin Sago 205f18e848 It looks like you’re writing a letter 2017-05-07 17:39:01 +01:00
Benjamin Sago 4335f1978c Low-hanging clippy fruit 2017-05-07 17:15:22 +01:00