Commit graph

38 commits

Author SHA1 Message Date
Lucas CHOLLET
3a95c8111d LibCore: Allow MappedFile to make File leak its fd 2023-02-16 10:56:01 +00:00
Tim Schumacher
606a3982f3 LibCore: Move Stream-based file into the Core namespace 2023-02-13 00:50:07 +00:00
Tim Schumacher
d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00
Karol Kosek
b810f7f88a LibCore: Implement File::can_delete_or_move()
Besides from a general check if a file's directory has write
permissions, this also checks if the directory has set a sticky bit,
meaning that only file owners and the directory owner can remove or move
files in such directory. It's being used in /tmp for example.
2023-01-24 20:13:30 +00:00
Tim Schumacher
8455d58a44 LibCore: Use a StringView for the file path in File::remove
This allows us to use our nice syscall wrappers, avoids some accidental
string copying, and starts to unlink us from the old DeprecatedString.
2022-12-23 10:38:14 -05:00
Tim Schumacher
9805f73704 LibCore: Remove the force parameter from File::remove
About half of the usages were not using `force` anyways, and the other
half presumably just got confused about what "force" really means in
this context (which is "ignore nonexistent files").

The only 'legitimate' user, which is `rm`, instead now handles this
completely internally instead.
2022-12-23 10:38:14 -05:00
Tim Schumacher
355e761a02 LibCore: Let File::remove return a normal ErrorOr
Having the file path in there is nice, but it makes us incompatible with
comfortable error propagation in everything that isn't File::remove.
2022-12-23 10:38:14 -05:00
Lucas CHOLLET
cfb0e1bdb2 LibCore: Add fd overload of File::is_directory and File::is_device 2022-12-14 18:26:25 +00:00
Tim Schumacher
2fc2025f49 LibCore: Move Core::Stream::File::exists() to Core::File
`Core::Stream::File` shouldn't hold any utility methods that are
unrelated to constructing a `Core::Stream`, so let's just replace the
existing `Core::File::exists` with the nicer looking implementation.
2022-12-08 12:52:14 +00:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Sam Atkins
120e5aeca4 LibCore: Actually tell people to stop using Core::File in new code
Otherwise, we keep getting new code merged that uses it, which requires
fixing later.
2022-09-20 07:48:45 -04:00
Tim Schumacher
5f99934dce Userland: Consolidate most PATH resolving into a single implementation
We previously had at least three different implementations for resolving
executables in the PATH, all of which had slightly different
characteristics.

Merge those into a single implementation to keep the behaviour
consistent, and maybe to make that implementation more configurable in
the future.
2022-08-23 19:00:04 +01:00
Tim Schumacher
39a3775f48 Userland: Rely on a single authoritative source for the default PATH 2022-08-23 19:00:04 +01:00
Samuel Bowman
7b8088c78d LibCore: Add File::is_{block,char}_device() helpers
The existing File::is_device() helpers don't distinguish between
block and char devices. This commit adds File::is_block_device() and
File::is_char_device() helpers which are more specific.
2022-07-21 20:13:44 +01:00
Tim Schumacher
69e0b8dbb7 LibCore: Make copying permissions, ownership and timestamps combineable 2022-07-14 00:24:24 +01:00
kleines Filmröllchen
5319e3a03f LibCore+Userland: Remove File::ensure_parent_directories
We have a much safer and more powerful alternative now, so let's move
the few users over.
2022-04-11 00:08:48 +02:00
Kenneth Myhra
4a57be824c Userland+Tests: Convert File::read_link() from String to ErrorOr<String>
This converts the return value of File::read_link() from String to
ErrorOr<String>.

The rest of the change is to support the potential of an Error being
returned and subsequent release of the value when no Error is returned.
Unfortunately at this stage none of the places affected can utililize
our TRY() macro.
2022-03-24 11:57:51 +01:00
Tim Schumacher
62f0fa818d LibCore: Add File::ensure_directories() 2022-03-19 10:26:33 -07:00
Tim Schumacher
80cb44afae Everywhere: Move shared library checks into a common function
While we're at it, unify the various different conditions that are
scattered accross the codebase.
2021-11-10 14:42:49 +01:00
Andreas Kling
a7f1f1c34b LibCore: Use ErrorOr<T> for Core::File::open() 2021-11-08 00:35:27 +01:00
Andreas Kling
fac2550143 LibCore: Use ErrorOr<T> for Core::File::size() 2021-11-08 00:35:27 +01:00
Andreas Kling
4a2b718ba2 LibCore: Use ErrorOr<T> for Core::File::copy_file() 2021-11-08 00:35:27 +01:00
Andreas Kling
c7e62d448c LibCore: Use ErrorOr<T> for Core::File::remove()
This function returns a subclass of Error, which is now possible.
2021-11-08 00:35:27 +01:00
Andreas Kling
b2170c11a4 LibCore: Use ErrorOr<T> for Core::File::link_file() 2021-11-08 00:35:27 +01:00
Leandro Pereira
73924f9416 LibCore: Add File::size()
Returns the size in bytes for a file path given its filename. Useful
when file size is needed without having to open the file to query it
using fstat() or seeking to the end.
2021-10-25 23:37:18 +02:00
Andreas Kling
13f4890c38 LibCore: Make Core::File::open() return OSError in case of failure 2021-08-20 15:31:46 +02:00
Jean-Baptiste Boric
8cc8d72619 LibCore: Implement preserve flag for file/directory copy 2021-08-18 20:30:46 +02:00
Timothy
3cc0283eac LibCore: Convert File to east-const style 2021-07-14 14:35:16 +04:30
Timothy
068802d58d LibCore: Add File method to determine absolute path
This will generate absolute paths lexically rather than through a call
to realpath. The motivation for this is to generate absolute paths for
non-existent files in unveil calls, as realpath will not work if the
file does not exist.
2021-07-14 14:35:16 +04:30
Timothy
3ae64c7c3d LibCore: Add File method to determine current working directory 2021-07-14 14:35:16 +04:30
Ariel Don
3289b6a887 LibCore: Implement File::is_link()
It was already possible to check if a path was a directory or a device.
Now, it is possible to check if a path is a link in a similar manner.
2021-07-12 19:15:19 +04:30
Timothy
60f84f3154 LibCore: Add method to leak fd from File
This will let other code use the fd while making sure the fd isn't
automatically closed by Core::File's destructor
2021-07-04 11:44:47 +04:30
Ali Mohammad Pur
a91a49337c LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
2021-05-12 11:00:45 +01:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
a1a6d30b54 LibCore: Make File take String instead of StringView 2021-04-17 01:27:31 +02:00
Idan Horowitz
aff774c8ac LibCore: Add Core::File is_device() helpers
The helpers check if the file is a block device or a character device
via stat and fstat.
2021-03-30 11:29:52 +02:00
Mițca Dumitru
919492945e LibCore: Add file management helpers to reduce code duplication
FileManager, cp, mv, rm had some duplicated code, implementing basic
file management operations. This patch creates adds functions that try
to provide an interface suited for all these programs, but this patch
does not make them be used throughout the Userland.

They are added to Core::File following the example of functions such as
read_link/real_path_for.
2021-02-21 18:14:29 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Renamed from Libraries/LibCore/File.h (Browse further)