Skip to content

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

Merged
dlang-bot merged 4 commits into
dlang:masterfrom
jercaianu:disk
Jun 28, 2019
Merged

Fix Issue 16487 - Add function to obtain the available disk space#5776
dlang-bot merged 4 commits into
dlang:masterfrom
jercaianu:disk

Conversation

@jercaianu

Copy link
Copy Markdown
Contributor

removed redundant line

@dlang-bot

dlang-bot commented Oct 10, 2017

Copy link
Copy Markdown
Contributor

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"

Comment thread std/file.d Outdated
Comment thread std/file.d Outdated
Comment thread std/file.d Outdated
Comment thread std/file.d Outdated
Comment thread std/file.d
Comment thread std/file.d Outdated
Comment thread std/file.d
Comment thread std/file.d Outdated
@jercaianu

Copy link
Copy Markdown
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

@ghost ghost left a comment

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Contributor

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

n8sh commented Mar 27, 2018

Copy link
Copy Markdown
Member

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?

Comment thread std/file.d Outdated
@quickfur

Copy link
Copy Markdown
Member

Tagging @andralex since this adds a new public symbol.

@quickfur

Copy link
Copy Markdown
Member

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

@jercaianu

jercaianu commented Mar 28, 2018

Copy link
Copy Markdown
Contributor Author

@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

Comment thread std/file.d Outdated
Comment thread std/file.d Outdated
Comment thread 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
Copy Markdown
Contributor

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

Comment thread std/file.d Outdated
Comment thread std/file.d Outdated
Comment thread std/file.d
@wilzbach

Copy link
Copy Markdown
Contributor

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.

Comment thread std/file.d
assert(space > 0);

assertThrown!FileException(getAvailableDiskSpace("ThisFileDoesNotExist123123"));
}

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

@jercaianu what's with the linux32 failure?

@andralex

Copy link
Copy Markdown
Member

@JackStouffer good to go?

@n8sh

n8sh commented Apr 18, 2018

Copy link
Copy Markdown
Member

@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
Copy Markdown
Contributor

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

tibi77 commented Mar 8, 2019

Copy link
Copy Markdown
Contributor

Why is this stil open?

@thewilsonator

thewilsonator commented Mar 8, 2019

Copy link
Copy Markdown
Contributor

Because it fails on FreeBSD.

@thewilsonator

Copy link
Copy Markdown
Contributor

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

Comment thread std/file.d Outdated
}
else version (Posix)
{
import std.string : toStringz;

Copy link
Copy Markdown
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
Copy Markdown
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.