Bug ensure_dir?

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
erict
Messages: 56
Registration: December 22, 2017 - 7:09 PM

July 22, 2018 - 1:22 PM

Good morning,

Wapt version 1.5

I tried using the `setuphelper ensure_dir` in a package, and I encountered a malfunction:

In fact, the command `ensure_dir('C:\Programmes\Ape')` did nothing. I tested it in a Python console with all possible combinations (putting "r" before 'C:\Programmes...', using `Programmes` instead of `Programmes`...), nothing worked.

So, I looked at the function's code and ran some tests directly in Python:
(of course the directory C:\Program Files does not exist)

Code: Select all

>>> ## Test 1 :
>>> d=path.dirname('C:\program rrr')
>>> d
'C:\\'
>>> path.isdir(d)
True

>>> ## Test 2 :
>>> d="C:\Program rrr"
>>> d
'C:\\Program rrr'
>>> path.isdir(d)
False

>>> ##Test 3 :
>>> d="C:\Program Files"
>>> d
'C:\\Program Files'
>>> path.isdir(d)
True

In test 1, we see that if `d` is declared as `path.dirname`, the `isdir()` function always returns `True`, even if the path doesn't exist. (The response I get when I ask it to display `d` is a bit surprising, but later on, we see that this doesn't seem to be the cause of the problem, even though it's already problematic.)
In test 2, we see that if d is declared as a string and the path does not exist, we do indeed get False.
In test 3, we see that, on the other hand, if the path exists when d is declared as a string, we do get a True.

It seems to me, therefore, that in ensure_dir(), rather than using

Code: Select all

d = os.path.dirname(filename)
You should use

Code: Select all

d = filename
Or, you can directly use the filename variable, since `d`, in this case, doesn't seem to serve much purpose, except perhaps to convert filename to a string:

Code: Select all

d = str(filename)
Sincerely
E. Trezel
erict
Messages: 56
Registration: December 22, 2017 - 7:09 PM

July 22, 2018 - 5:10 PM

Hello again,

I pushed my investigations a little further, very surprised to find a bug in a function that must be used quite a lot, and also by the display of the variable d in my test 1, which is in fact the cause of the problem:

Code: Select all

>>> ## Test 1 :
>>> d=path.dirname('C:\program rrr')
>>> d
'C:\\'
>>> path.isdir(d)
True
The response from isdir() is logical, since d is equal to C:, and C: does exist.
So I looked for which syntax(es) gave the value of d that was the one I was looking for.
Using the "intuitive" values ​​(normal Windows path, with or without a "\" at the end), it doesn't actually work:

Code: Select all


>>> d = path.dirname('C:\Program Files')
>>> d
'C:\\'

>>> d = path.dirname('C:\ProgramFiles\')
	File "<stdin>", line 1
		d = path.dirname('C:\ProgramFiles\')
									^
SyntaxError:  EOL while scanning string literal

Note: Adding 'r' before the parameter (e.g., d = path.dirname(r'C:\ProgramFiles\')) did not change my results.
The values ​​for which I managed to get this function to work correctly (da is the desired value, and path.isdir() returns the correct value) are:

Code: Select all

## Chemin Windows "normal", et on échappe le dernier "\" :
d = path.dirname('C:\Program Files\\')
## Chemin Windows "normal", et on ajoute un espace après le dernier "\" :
d = path.dirname('C:\Program Files\ ')
## Chemin Windows "normal", et on remplace le dernier "\" par un "/" :
d = path.dirname('C:\Program Files/')
## Chemin style "Linux", avec des "/" et non des "\" (et "/" à la fin obligatoire) :
d = path.dirname('C:/Program Files/')
## 
This is not mentioned in the documentation for ensure_dir() (https://wapt.tranquil.it/wapt/nightly/a ... ensure_dir), and is not taken into account in the code, unless I've missed something.
I also found nothing in the documentation for path.dirname() or isdir() on the Python side.

Hopefully this helps...
AND.
Locked