No such file or directory - bug due to filepath length?

F

fensterblick

Hello again from another relative newcomer. I am encountering a weird
issue when trying to write out a file to disk. I get a "No such file
or directory" error if the file path is greater than or equal to 194
characters. I have no problem with lengths less than 194 characters. I
am using Ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32].

Here is a very simplified version of my code that causes the issue:

backup_dir = "backup\\deployer\\172.00.00.00\\opt\\jboss\\server\
\default\\deploy\\birtdaemon.war\\WEB-INF\\plugins\
\org.eclipse.birt.report.data.oda.jdbc_2.1.1.v20070205-1728\\drivers\
\"
FileUtils.mkdir_p (backup_dir)
this_location_works = backup_dir + "abcdefghijklmnopqrst"
this_location_fails = backup_dir + "abcdefghijklmnopqrstu"
File.open( this_location_works, "wb" ) { |f| f.write "hello hello
hello..." }
File.open( this_location_fails, "wb" ) { |f| f.write "can't figure
out why this won't work!" }


As you can see, I am able to create one file but not the other. Is
this a bug or is there an error with my code? I searched through the
newgroup but I can't find any previous problems related to filepath
lengths.

Thanks for any help - I have to demo a script this week and I came
across this issue during testing. On a less urgent matter, I tried to
debug this code using ruby-debug, but I can't step into File.open().
How does one step through File.open()? My guess is that I cannot step
into it because it might not be written in Ruby (perhaps C?). If it is
written in C, where can I find the source code for it? Again, I'm a
newbie to Ruby so don't feel bad about including seemingly obvious
details in an answer.
 
A

Alex LeDonne

Hello again from another relative newcomer. I am encountering a weird
issue when trying to write out a file to disk. I get a "No such file
or directory" error if the file path is greater than or equal to 194
characters. I have no problem with lengths less than 194 characters. I
am using Ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32].

Here is a very simplified version of my code that causes the issue:

backup_dir = "backup\\deployer\\172.00.00.00\\opt\\jboss\\server\
\default\\deploy\\birtdaemon.war\\WEB-INF\\plugins\
\org.eclipse.birt.report.data.oda.jdbc_2.1.1.v20070205-1728\\drivers\
\"

Well, that's a relative path. I'll bet if you look at the FULL path,
you'll discover that the full path for the working example below is
255 characters, and the second is 256. What is the FULL path of
backup_dir?

-A
 
F

fensterblick

What is the FULL path of backup_dir?
The full path is:
C:\Documents and Settings\fensterb001\Desktop\projects
\eclipse_workspace\pwdmgr\backup\deployer\172.16.11.33\opt\jboss\server
\default\deploy\birtdaemon.war\WEB-INF\plugins
\org.eclipse.birt.report.data.oda.jdbc_2.1.1.v20070205-1728\drivers\

That is 239 characters. "abcdefghijklmnopqrst" is 20 characters long,
resulting in 259 total characters for the successfully created file.

If there is a 256 character limit, where is this limit referenced? I
can't seem to find any references to it in the Core Reference. In
Windows, we can easily create files with filepaths greater than 256
characters; I would also expect this case to be handled successfully
by File.open().

(Sidenote: I did move the backup directory to C:\backup, and that
worked around the issue)
 
A

Alex LeDonne

The full path is:
C:\Documents and Settings\fensterb001\Desktop\projects
\eclipse_workspace\pwdmgr\backup\deployer\172.16.11.33\opt\jboss\server
\default\deploy\birtdaemon.war\WEB-INF\plugins
\org.eclipse.birt.report.data.oda.jdbc_2.1.1.v20070205-1728\drivers\

That is 239 characters. "abcdefghijklmnopqrst" is 20 characters long,
resulting in 259 total characters for the successfully created file.

If there is a 256 character limit, where is this limit referenced? I
can't seem to find any references to it in the Core Reference. In
Windows, we can easily create files with filepaths greater than 256
characters; I would also expect this case to be handled successfully
by File.open().

(Sidenote: I did move the backup directory to C:\backup, and that
worked around the issue)

Well, I don't think the 'C:\' counts in the path length, as it's the
drive root. So I do belive this is a 256-character limit issue.

Yup... found it:

"Maximum Path Length

"In the Windows API, the maximum length for a path is MAX_PATH, which
is defined as 260 characters. A path is structured in the following
order: drive letter, colon, backslash, components separated by
backslashes, and a null-terminating character, for example, the
maximum path on the D drive is "D:\<256 chars>NUL". "

http://msdn2.microsoft.com/en-us/library/aa365247.aspx


That page also provides a possible workaround:

"The Unicode versions of several functions permit a maximum path
length of approximately 32,000 characters composed of components up to
255 characters in length. To specify that kind of path, use the "\\?\"
prefix.

" Note The maximum path of 32,000 characters is approximate,
because the "\\?\" prefix can be expanded to a longer string, and the
expansion applies to the total length.

"For example, "\\?\D:\<path>". To specify such a UNC path, use the
"\\?\UNC\" prefix. For example, "\\?\UNC\<server>\<share>". These
prefixes are not used as part of the path itself. They indicate that
the path should be passed to the system with minimal modification,
which means that you cannot use forward slashes to represent path
separators, or a period to represent the current directory. Also, you
cannot use the "\\?\" prefix with a relative path. Relative paths are
limited to MAX_PATH characters."

Good Luck!

-A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top