SchwabenCode / QuickIO

Faster with Files
MIT License
59 stars 16 forks source link

exception with pathnames relativ ( name\..\anothername\) #17

Closed KlausWilly closed 7 years ago

KlausWilly commented 7 years ago

Hello togehter

I am using QuickIO.Net version 2.6.2.0 from Nuget. in Linqpad. When working with long names and with relative Pathnames an exception occures. ex:

"\my.server\dir0\dir1\dir2\dir3\dir4" thats my basepath

now i do following:

var str = new QuickIOPathInfo( _Path + @"..\mydir5")

this raises an exception. The orginal DirectoryInfo can handle this. do think you can correct this? thanks a lot in advance

klaus

BenjaminAbt commented 7 years ago

string concatenation is not a good idea to generate path names / values. What's the value of _Path and what happens if you use Path.Combine instead of this string concatenation?

Path.Combine should handle this, not a path info. Even if DirectoryInfo is nice to clean path names in the background (which causes a performance drop).

KlausWilly commented 7 years ago

HI

I tried different things:

var test= QuickIOPath.Combine(@"\my.server\dir0\dir1\dir2\dir3\dir4",@"..\mydir5"); only gives "..\mydir5" also not working.

What works is this: IEnumerable ieFiles_1 = new DirectoryInfo(@"\my.server\dir0\dir1\dir2\dir3\dir4file://my.server/dir0/dir1/dir2/dir3/dir4" + @"..\mydir5" ").EnumerateFiles ("."); //concatenation OK When looking in DirectoryInfo there you find (@"\my.server\dir0\dir1\dir2\dir3\dir4file://my.server/dir0/dir1/dir2/dir3/dir4..\mydir5")

OK I figured out the Problem (both IO’s)

If combining “path”,”..\path“ is OK If combining “path”,”..\path“ is NOT OK If combining “path\”,”..\path“ is OK If combining “path\”,”..\path“ is not OK

It is the first Backslash on the second parameter what causes the error with combine.

But QuickIODirectory.EnumerateFiles (@"\my.server\dir0\dir1\dir2\dir3\dir4file://my.server/dir0/dir1/dir2/dir3/dir4" + @"..\mydir5")., "*", SearchOption.TopDirectoryOnly); is not working even if the Path syntactically is correct .

Very thanks for helping!!

Have a nice evening

Klaus

Von: Benjamin Abt [mailto:notifications@github.com] Gesendet: Dienstag, 24. Oktober 2017 17:58 An: SchwabenCode/QuickIO QuickIO@noreply.github.com Cc: Rumold, Klaus Klaus.Rumold@bizerba.com; Author author@noreply.github.com Betreff: Re: [SchwabenCode/QuickIO] exception with pathnames relativ ( name..\anothername) (#17)

string concatenation is not a good idea to generate path names / values. What's the value of _Path and what happens if you use Path.Combine instead of this string concatenation?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SchwabenCode/QuickIO/issues/17#issuecomment-339040174, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ARumPgi59pzrK3uAlHMkLxr-_iLiB637ks5svgjzgaJpZM4QEquz.


Bizerba SE & Co. KG, Sitz: Balingen, Amtsgericht Stuttgart HRA 410001, Persönlich haftende Gesellschafterin: Bizerba Management SE, Sitz: Balingen, Amtsgericht Stuttgart HRB 757896, Vorsitzender des Aufsichtsrates: Prof. Dr. Dr. Dr. h. c. Michael Ungethüm, Vorstand: Andreas W. Kraut (Vors.) - USt-IdNr. DE 144835104 - GLN 40 14116 00000 3 - WEEE-Reg.-Nr. DE 76764256

Der Inhalt dieser E-Mail ist vertraulich und ausschließlich für den bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte, dass jede Form der Kenntnisnahme, Veröffentlichung, Vervielfältigung oder Weitergabe des Inhalts dieser E-Mail unzulässig ist. Wir bitten Sie, sich in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen sowie die Originalnachricht zu löschen und alle Kopien hiervon zu vernichten.

This e-mail message including any attachments is for the sole use of the intended recipient(s) and may contain privileged or confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please immediately contact the sender by reply e-mail and delete the original message and destroy all copies thereof.

BenjaminAbt commented 7 years ago

Ya but what happens if you stop using string concat and use Path.Combine instead?

var p = Path.Combine(@"\\my.server\dir0\dir1\dir2\dir3\dir4",  @"\..\mydir5");
QuickIODirectory.EnumerateFiles(p);

It is by design that there is no parameter cleaning. This costs a lot performance. It is highly highly recommended to not use string concat to build paths!

KlausWilly commented 7 years ago

Good morning Benjamin;

As i said before: it throws an exception!

QuickIODirectory.EnumerateFiles(@\my.server\dir0\dir1\dir2\dir3\dir4..\mydir5file://my.server/dir0/dir1/dir2/dir3/mydir5 ,”*”, SearchOption.TopDirectoryOnly);

Is NOT working.

QuickIODirectory.EnumerateFiles(@\my.server\dir0\dir1\dir2\dir3\mydir5file://my.server/dir0/dir1/dir2/dir3/mydir5 ,”*”, SearchOption.TopDirectoryOnly);

IS working.

I think the Problem is the relative Path “..\”. If I take the Path absolute everything works OK

Best regards Klaus

Von: Benjamin Abt [mailto:notifications@github.com] Gesendet: Mittwoch, 25. Oktober 2017 14:55 An: SchwabenCode/QuickIO QuickIO@noreply.github.com Cc: Rumold, Klaus Klaus.Rumold@bizerba.com; Author author@noreply.github.com Betreff: Re: [SchwabenCode/QuickIO] exception with pathnames relativ ( name..\anothername) (#17)

Ya but what happens if you stop using string concat and use Path.Combine instead?

var p = Path.Combine(@"\my.server\dir0\dir1\dir2\dir3\dir4", @"..\mydir5");

QuickIODirectory.EnumerateFiles(p);

It is by design that there is no clean a parameter. This costs a lot performance. It is highly highly recommended to not use string concat to build paths!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SchwabenCode/QuickIO/issues/17#issuecomment-339320323, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ARumPl3pYIIEnIB4JAWQNP4YirgWDs7qks5svy-kgaJpZM4QEquz.


Bizerba SE & Co. KG, Sitz: Balingen, Amtsgericht Stuttgart HRA 410001, Persönlich haftende Gesellschafterin: Bizerba Management SE, Sitz: Balingen, Amtsgericht Stuttgart HRB 757896, Vorsitzender des Aufsichtsrates: Prof. Dr. Dr. Dr. h. c. Michael Ungethüm, Vorstand: Andreas W. Kraut (Vors.) - USt-IdNr. DE 144835104 - GLN 40 14116 00000 3 - WEEE-Reg.-Nr. DE 76764256

Der Inhalt dieser E-Mail ist vertraulich und ausschließlich für den bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte, dass jede Form der Kenntnisnahme, Veröffentlichung, Vervielfältigung oder Weitergabe des Inhalts dieser E-Mail unzulässig ist. Wir bitten Sie, sich in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen sowie die Originalnachricht zu löschen und alle Kopien hiervon zu vernichten.

This e-mail message including any attachments is for the sole use of the intended recipient(s) and may contain privileged or confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please immediately contact the sender by reply e-mail and delete the original message and destroy all copies thereof.

BenjaminAbt commented 7 years ago

I mistaken the method name. Please use GetFullPath instead of Combine.

var p = Path.GetFullPath (@"\\my.server\dir0\dir1\dir2\dir3\dir4" +  @"\..\mydir5");
QuickIODirectory.EnumerateFiles(p);

In this case string concat has no effect because GetFullPath is cleaning the path, but it doesn't hurt if you use Combine instead of concat in general.

KlausWilly commented 7 years ago

OK; that works; Thanks a lot,

But I anyway would call it a BUG in the library, because it works with the original version of MS

Have a good Day klaus

Von: Benjamin Abt [mailto:notifications@github.com] Gesendet: Donnerstag, 26. Oktober 2017 09:56 An: SchwabenCode/QuickIO QuickIO@noreply.github.com Cc: Rumold, Klaus Klaus.Rumold@bizerba.com; Author author@noreply.github.com Betreff: Re: [SchwabenCode/QuickIO] exception with pathnames relativ ( name..\anothername) (#17)

I mistaken the method name.

Please use GetFullPath instead of combine.

var p = Path.GetFullPath (@"\my.server\dir0\dir1\dir2\dir3\dir4file://my.server/dir0/dir1/dir2/dir3/dir4" + @"..\mydir5");

QuickIODirectory.EnumerateFiles(p);

In this case string concat has no effect because GetFullPath is cleaning the path, but it doesn't hurt if you use Combine instead of concat.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SchwabenCode/QuickIO/issues/17#issuecomment-339583217, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ARumPvazZ3nKo824fqLbiag6xMcfBkoxks5swDsjgaJpZM4QEquz.


Bizerba SE & Co. KG, Sitz: Balingen, Amtsgericht Stuttgart HRA 410001, Persönlich haftende Gesellschafterin: Bizerba Management SE, Sitz: Balingen, Amtsgericht Stuttgart HRB 757896, Vorsitzender des Aufsichtsrates: Prof. Dr. Dr. Dr. h. c. Michael Ungethüm, Vorstand: Andreas W. Kraut (Vors.) - USt-IdNr. DE 144835104 - GLN 40 14116 00000 3 - WEEE-Reg.-Nr. DE 76764256

Der Inhalt dieser E-Mail ist vertraulich und ausschließlich für den bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte, dass jede Form der Kenntnisnahme, Veröffentlichung, Vervielfältigung oder Weitergabe des Inhalts dieser E-Mail unzulässig ist. Wir bitten Sie, sich in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen sowie die Originalnachricht zu löschen und alle Kopien hiervon zu vernichten.

This e-mail message including any attachments is for the sole use of the intended recipient(s) and may contain privileged or confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please immediately contact the sender by reply e-mail and delete the original message and destroy all copies thereof.

BenjaminAbt commented 7 years ago

You can call it bug, but that's it. I say it is by design because QuickIO is and never will be responsible for your input. This costs performance. Yes this differs from System.IO but as I said: by design.

You are responsible for the input - or you'll get an exception. If you handle paths correctly, QuickIO works fine.