Skip to content

Conversation

mihails-strasuns
Copy link

Partial implementation to #482 (does not add cache locks)

It currently includes only posix implementation - I need some hints to know how it should be done on Windows correctly.

@mihails-strasuns
Copy link
Author

It also does not change parts which generate randomly-named directories inside /tmp - it seems to work good enough as it is.

@andralex
Copy link
Member

Error: cannot read file test/1-staticLib-simple/aFcake-dub_test_root.d

What's that?

pattern[prefix.length .. $-1] = name[];
pattern[$-1] = '\0';

auto handle = mkstemps(pattern.ptr, to!int(name.length + 1));
Copy link
Member

Choose a reason for hiding this comment

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

Does that work on Windows?

Copy link
Author

Choose a reason for hiding this comment

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

No of course. I have never written a single program for Windows and will need to do some research on WinAPI to figure out the alternative.

@mihails-strasuns
Copy link
Author

Ok, after some investigation of online docs have added Windows version. Can't test it locally though so will rely on tester :(

@mihails-strasuns
Copy link
Author

Oh, there is no Windows slave in dub travis job?

@mihails-strasuns
Copy link
Author

Well, it is green now but I really need someone with Windows machine to verify it works there too - I don't have much trust in my blind coding for other platforms.


auto dir = getTempDir().toStringz();
auto name = prefix.toStringz();
char[MAX_PATH] output;
Copy link
Member

Choose a reason for hiding this comment

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

= void

Copy link
Author

Choose a reason for hiding this comment

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

Updated

@MartinNowak
Copy link
Member

Windows error

source\dub\internal\utils.d(71): Error: None of the overloads of 'toStringz' are callable using argument types (Path), candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\string.d(169):        std.string.toStringz(const(char)[] s)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\string.d(212):        std.string.toStringz(string s)
source\dub\internal\utils.d(75): Error: no property 'ptr' for type 'immutable(char)*'
source\dub\internal\utils.d(78): Error: no property 'fromStrinz' for type 'char[260]'

@mihails-strasuns
Copy link
Author

@MartinNowak thanks, fixed ones in the paste.

@MartinNowak
Copy link
Member

Will this allow us to get your Jenkins running for the upcoming release?

@mihails-strasuns
Copy link
Author

I hope so. It seemed to work apart from failing parallel jobs but hard to foresee what will go wrong when more projects get added ;)

@MartinNowak MartinNowak merged commit 49502df into dlang:master Feb 3, 2015
MartinNowak added a commit that referenced this pull request Feb 3, 2015
Use unique names for temporary files
@MartinNowak
Copy link
Member

After all the trouble with GetTempFileNameW and toUTF16z, I get something like this.
C:/Users/dawg/AppData/Local/Temp/dubC3E2.tmp.rsp
As the docs say, it uses up to 3 chars of the prefix and apparently only 4 random digits.
It's also not necessarily unique as we have to append the file extension.

So I just generated a UUID based name instead.
This functionality is really missing from phobos.
Issue 13996 – Function for returning a temporary file with a randomly generated name where the name can be accessed

else version (Windows)
{
import core.sys.windows.windows : MAX_PATH;
import std.string : toStringz, fromStringz;

Choose a reason for hiding this comment

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

Spaces!

@mihails-strasuns
Copy link
Author

Ouch, I didn't realize this WinAPI function is that useless.

This functionality is really missing from phobos.

I can see why, considering how incompatible different OS primitives seem to be.

@MartinNowak
Copy link
Member

Ouch, I didn't realize this WinAPI function is that useless.

But it does guarantee uniqueness, until we append the extension.

@mihails-strasuns
Copy link
Author

Uniqueness alone is not enough to make it useful - with posix function manual appending is not even needed because it is flexible with filename template.

Simply having a random filename you can't control is not much better than existing tempfile.

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

Successfully merging this pull request may close these issues.

4 participants