Skip to content

Fix Issue 16487 - Add function to obtain the available disk space #5776

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

Merged
merged 4 commits into from
Jun 28, 2019

Conversation

jercaianu
Copy link
Contributor

removed redundant line

@dlang-bot
Copy link
Contributor

dlang-bot commented Oct 10, 2017

Thanks for your pull request and interest in making D better, @jercaianu! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
16487 enhancement Add function to obtain the available disk space

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#5776"

@jercaianu
Copy link
Contributor Author

Thanks for the comments, I'll shortly look into them as soon as I figure out what's going on with the FreeBSD failure.

Also, since we're here, do you think it would be a good idea to add functionality for getFreeDiskSpace or getDiskSpaceCapacity (similar to boost::filesystem) ?

Thanks,
Alex

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good so far
just a little change related to version and it's okay.

@jercaianu
Copy link
Contributor Author

I have figured out what's wrong with the FreeBSD test.
It seems that statvfs does not work on FreeBSD as expected, but statfs works.

The question is now, should I add statfs in the runtime, or just assume return 0 for FreeBSD?

Thanks,
Alex

@wilzbach
Copy link
Member

The question is now, should I add statfs in the runtime, or just assume return 0 for FreeBSD?

Extending the bindings in druntime is almost always welcome as *BSD is vastly lacking behind in terms of maintenance manpower (iirc only one or two of the core people around here use it regularly).

@n8sh
Copy link
Member

n8sh commented Mar 27, 2018

The question is now, should I add statfs in the runtime, or just assume return 0 for FreeBSD?

You throw an exception on failure, so isn't the correct behavior to throw an exception?

@quickfur
Copy link
Member

Tagging @andralex since this adds a new public symbol.

@quickfur
Copy link
Member

ping @jercaianu This has stalled for far too long. Any chance we can get things moving again?

@jercaianu
Copy link
Contributor Author

jercaianu commented Mar 28, 2018

@quickfur
Hi, the reason I can't move forward with this, is because I need to add statvfs on FreeBSD [1].
However, this in turn, is blocked by this one [2].

If statfs would be added, then I can easily finish this.

[1] - dlang/druntime#1937
[2] - https://issues.dlang.org/show_bug.cgi?id=17596#c8

std/file.d Outdated
return GetDiskFreeSpaceExW(path.tempCStringW(), &freeBytesAvailable, null, null);
} ();
enforce(err != 0,
new FileException(text("Cannot get available disk space: ", GetLastError())));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a look at the default constructor of FileException:

    version(Windows) this(in char[] name,
                          uint errno = .GetLastError(),
                          string file = __FILE__,
                          size_t line = __LINE__) @safe
    {

tl;dr: use cenforce

@wilzbach
Copy link
Member

As this is a new function, it might be worthwhile to check this PR.
The idea is to mark it as unstable (in some way) for a few releases.

assert(space > 0);

assertThrown!FileException(getAvailableDiskSpace("ThisFileDoesNotExist123123"));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do more tests here. Simple create a directory with deleteme and write files to it and check the resulting file size (if this varies on Windows, version(Posix) it).

Example:

https://dlang.org/phobos-prerelease/std_file.html#mkdir

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be a bit excessive - we'd be testing the OS primitives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on what you have running on your system, the size could vary a lot.
This may cause such a test to fail at times, despite everything running correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should test that the function works for null and "" (empty strings) input. See e.g. https://issues.dlang.org/show_bug.cgi?id=14980

@jercaianu
Copy link
Contributor Author

This should be alright now

@wilzbach wilzbach removed the @andralex label Apr 6, 2018
@wilzbach wilzbach dismissed their stale review April 6, 2018 14:36

I would still prefer that we either move this to std.experimental for one release or mark it as unstable in the docs somehow, s.t. we don't accidentally end up releasing something that we can't change anymore (as we used to do in the past), but I won't block this PR further.

@andralex
Copy link
Member

@jercaianu what's with the linux32 failure?

@andralex
Copy link
Member

@JackStouffer good to go?

@n8sh
Copy link
Member

n8sh commented Apr 18, 2018

@andralex Appears unrelated.

posix.mak:381: recipe for target 'unittest/std/concurrency.run' failed
make[1]: *** [unittest/std/concurrency.run] Error 139

@JackStouffer
Copy link
Member

I won’t be able to review this until late tonight. Please merge without my review if you think this is good to go.

@tibi77
Copy link
Contributor

tibi77 commented Mar 8, 2019

Why is this stil open?

@thewilsonator
Copy link
Contributor

thewilsonator commented Mar 8, 2019

Because it fails on FreeBSD.

@thewilsonator
Copy link
Contributor

@n8sh this probably needs a rebase to pass on circle.

std/file.d Outdated
}
else version (Posix)
{
import std.string : toStringz;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function's argument type was changed from string to const char[] it should probably use tempCString instead of toStringz in the Posix path. toStringz always allocates if it is given a const char[].

@n8sh n8sh dismissed JackStouffer’s stale review June 23, 2019 23:13

Tests are no longer disabled on FreeBSD.

@dlang-bot dlang-bot merged commit 6010a7c into dlang:master Jun 28, 2019
@JohanEngelen
Copy link
Contributor

#5776 (comment) ?

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

Successfully merging this pull request may close these issues.