Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AFPP is implemented #6

Closed
hasufell opened this issue Jul 17, 2022 · 12 comments
Closed

AFPP is implemented #6

hasufell opened this issue Jul 17, 2022 · 12 comments

Comments

@hasufell
Copy link

@xtendo-org
Copy link
Owner

Good. Thanks for letting me know. I guess this is the beginning of a long journey to implement everything, like callProcess or getDirectoryFiles, on the new OsPath type.

This means, for Unix, having to re-implement stuff on ShortByteString instead of ByteString. I don't know how much work that will be.

@xtendo-org
Copy link
Owner

@hasufell No, it's not done. Perhaps I wasn't clear enough. My apologies. Let me clarify. What you are thinking of is probably forkProcess, not callProcess. forkProcess returns a ProcessID. callProcess returns an ExitCode.

(By the way, I don't know if forkProcess has fixed #1.)

The point of this package is that, "unix" does not provide high-level functions like readProcessWithExitCode or getDirectoryFilesRecursive. It never did. "process" and "directory" did provide them, but only for FilePath (String), and that's why I made this package.

In other words, we have readProcessWithExitCode for String and ByteString, and now we need readProcessWithExitCode for ShortByteString. It shouldn't be overly difficult. Some of the code in rawfilepath (this repo) may be translatable almost without any change.

When you look at the function name, readProcessWithExitCode, you'd immediately notice this is higher-level than the responsibility of the "unix" package. But we need this function somewhere. (I think functions like callProcess or readProcessWithExitCode are so obviously necessary if you are to do something practical with Haskell.) Do you think "filepath" would accept them? If not, we will need to make a new package.

Either way, I'm glad OsPath is here, and I'm willing to give any help I can.

@hasufell
Copy link
Author

hasufell commented Sep 1, 2023

It never did. "process" and "directory" did provide them, but only for FilePath (String), and that's why I made this package.

Directory package is already migrated. Process not.

@woffs
Copy link

woffs commented Sep 1, 2023

A bit off-topic maybe, but don't forget "hinotify".

@joeyh
Copy link

joeyh commented Oct 25, 2023

Note that base does not implement AFPP yet, so things like withFile are still needed from this library.

@hasufell
Copy link
Author

@xtendo-org
Copy link
Owner

xtendo-org commented Oct 26, 2023

Yeah well I think what joeyh really means is

  • In order to avoid the issues with FilePath (filesystem encoding, performance, etc.) you need to use either RawFilePath (this package) or OsPath (AFPP)
  • base provides neither, and for withFile, withFile (RawFilePath) is the only option
  • (If base implemented AFPP, it would have implemented withFile for OsPath as well, which is what joeyh meant, I think)
  • (But base unfortunately doesn't, so RawFilePath remains relevant)

There is no withFile for OsPath at the moment, am I right? The functions you linked seem to take FilePath (String), not OsPath (ShortByteString).

But implementing withFile for OsPath shouldn't be too difficult. At least it should be easier than callProcess for OsPath.

@hasufell
Copy link
Author

There is no withFile for OsPath

That's the issue. Because that function doesn't make sense.

You have to distinguish between platforms when going to the original bytes, because they have fundamentally different shape (char vs wide char array).

Failure to do so will lead to broken code.

Can you explain precisely what the problem is?

@xtendo-org
Copy link
Owner

xtendo-org commented Oct 27, 2023

@hasufell Well, to make sure we're on the same page... Here's one scenario I can think of:

  1. The programmer obtains a list (or array, or whatever) of files in a directory, using something like... Let's say getDirectoryFileList
  2. The programmer wants to apply some logic for all files
  3. The programmer uses withFile to obtain a file handle and interact with the file content

I think this is a pretty realistic use case. Linting, spell correcting, graphics texture file manipulation, and so on. RawFilePath allows this. The advantage of AFPP would be to let you write code that works on Windows as well.

The internal representation of the file content would matter, because that's the sequence of bytes the programmer is actually manipulating. But the internal representation of the file path (char vs wide char array) shouldn't matter, because the list is not constructed by the programmer. It's from the OS.

It could be a char array or a wide char array, and the programmer doesn't care; What is returned by getDirectoryFileList will simply be passed to withFile. The path bytes are intact.

Hopefully withFile for OsPath makes a bit more sense now?

@hasufell
Copy link
Author

Oh... I confused withFile with withFilePath.

If you had read the blog post I linked, you'd know withFile is indeed already implemented: https://hackage.haskell.org/package/file-io-0.1.0.1/docs/System-File-OsPath.html#v:withFile

@xtendo-org
Copy link
Owner

Oh well good. Excellent. Thanks.

@joeyh Check it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants