You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Denis Linine <li...@freesurf.ch> on 2008/02/23 17:08:48 UTC

getOutputStream method of the org.apache.jackrabbit.core.fs.mem.MemoryFileSystem question

Hello,

I had a look at the getOutputStream method of the 
org.apache.jackrabbit.core.fs.mem.MemoryFileSystem class, its code is 
presented below:

public OutputStream getOutputStream(String filePath) throws 
FileSystemException
{          
        String folderPath = filePath;
        if (filePath.lastIndexOf(FileSystem.SEPARATOR) > 0)
        {
            folderPath = filePath.substring(0, filePath.lastIndexOf("/"));
        }
        else
        {
            folderPath = "/";
        }
        assertIsFolder(folderPath);

        final MemoryFile file = new MemoryFile();
        entries.put(filePath, file);

        return new FilterOutputStream(new ByteArrayOutputStream())
        {
            public void close() throws IOException
            {
                out.close();
                file.setData(((ByteArrayOutputStream) out).toByteArray());
            }
        };
    }

I might be wrong, but it seems that if the filePath passed points to an 
existing folder and not to a file - the folder will be replaced with a 
newly created file. Unfortunately, at the moment being I do not have JR 
build environment set up to test practically whether this is really the 
case. Might be some check whether the path passed really points to a 
file should be added.

Best regards
Denis Linine

Re: getOutputStream method of MemoryFileSystem question

Posted by Denis Linine <li...@freesurf.ch>.
Hi Stefan, I created a related JIRA issue, thank you for tacking time 
for checking my suppositions.

Best regards
Denis Linine


Stefan Guggisberg wrote:
>   
>>  I suppose there is a similar problem with the move method of the same class:
>>  when looking in the code it seems that in can accept invalid destinations
>>  (still have no test environment, cannot verify whether this is the case in
>>  practice). For example, if there is a "somefolder/somefile" file and I call
>>  the method passing, say "somefolder/someotherfolder/somefile" as the
>>  destination. I suppose that the destination will be accepted by the code
>>  even if "somefolder/someotherfolder" is not an existing folder, then there
>>  will be a file having the "somefolder/someotherfolder/somefile" path within
>>  the file system having no "somefolder/someotherfolder" folder - the code
>>  should probably check whether the destination path is really a valid one.
>>     
>
> yup, i agree. do you mind creating another jira issue? ;)
>
> thanks
> stefan
>
>   

Re: getOutputStream method of the org.apache.jackrabbit.core.fs.mem.MemoryFileSystem question

Posted by Stefan Guggisberg <st...@gmail.com>.
On Mon, Mar 3, 2008 at 4:58 PM, Stefan Guggisberg
<st...@gmail.com> wrote:
> hi denis,
>
>
>  On Mon, Mar 3, 2008 at 7:02 AM, Denis Linine <li...@freesurf.ch> wrote:
>  >
>  >
>  >  Hello, I created a related JIRA issue.
>
>  thanks!
>
>
>  >  I suppose there is a similar problem with the move method of the same class:
>  >  when looking in the code it seems that in can accept invalid destinations
>  >  (still have no test environment, cannot verify whether this is the case in
>  >  practice). For example, if there is a "somefolder/somefile" file and I call
>  >  the method passing, say "somefolder/someotherfolder/somefile" as the
>  >  destination. I suppose that the destination will be accepted by the code
>  >  even if "somefolder/someotherfolder" is not an existing folder, then there
>  >  will be a file having the "somefolder/someotherfolder/somefile" path within
>  >  the file system having no "somefolder/someotherfolder" folder - the code
>  >  should probably check whether the destination path is really a valid one.
>
>  yup, i agree. do you mind creating another jira issue? ;)

thanks for creating JCR-1450!

cheers
stefan

>
>  thanks
>  stefan
>
>
>
>  >  Without the ability to test the issue practically, I am not sure whether
>  >
>  > this is really the case.
>  >
>  >  Best regards
>  >  Denis Linine
>  >  --
>  >  View this message in context: http://www.nabble.com/getOutputStream-method-of-the-org.apache.jackrabbit.core.fs.mem.MemoryFileSystem-question-tp15653797p15798179.html
>  >  Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.
>  >
>  >
>

Re: getOutputStream method of the org.apache.jackrabbit.core.fs.mem.MemoryFileSystem question

Posted by Stefan Guggisberg <st...@gmail.com>.
hi denis,

On Mon, Mar 3, 2008 at 7:02 AM, Denis Linine <li...@freesurf.ch> wrote:
>
>
>  Hello, I created a related JIRA issue.

thanks!

>  I suppose there is a similar problem with the move method of the same class:
>  when looking in the code it seems that in can accept invalid destinations
>  (still have no test environment, cannot verify whether this is the case in
>  practice). For example, if there is a "somefolder/somefile" file and I call
>  the method passing, say "somefolder/someotherfolder/somefile" as the
>  destination. I suppose that the destination will be accepted by the code
>  even if "somefolder/someotherfolder" is not an existing folder, then there
>  will be a file having the "somefolder/someotherfolder/somefile" path within
>  the file system having no "somefolder/someotherfolder" folder - the code
>  should probably check whether the destination path is really a valid one.

yup, i agree. do you mind creating another jira issue? ;)

thanks
stefan

>  Without the ability to test the issue practically, I am not sure whether
>
> this is really the case.
>
>  Best regards
>  Denis Linine
>  --
>  View this message in context: http://www.nabble.com/getOutputStream-method-of-the-org.apache.jackrabbit.core.fs.mem.MemoryFileSystem-question-tp15653797p15798179.html
>  Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.
>
>

Re: getOutputStream method of the org.apache.jackrabbit.core.fs.mem.MemoryFileSystem question

Posted by Denis Linine <li...@freesurf.ch>.

Hello, I created a related JIRA issue. 
I suppose there is a similar problem with the move method of the same class:
when looking in the code it seems that in can accept invalid destinations
(still have no test environment, cannot verify whether this is the case in
practice). For example, if there is a "somefolder/somefile" file and I call
the method passing, say "somefolder/someotherfolder/somefile" as the
destination. I suppose that the destination will be accepted by the code
even if "somefolder/someotherfolder" is not an existing folder, then there
will be a file having the "somefolder/someotherfolder/somefile" path within
the file system having no "somefolder/someotherfolder" folder - the code
should probably check whether the destination path is really a valid one.
Without the ability to test the issue practically, I am not sure whether
this is really the case.

Best regards
Denis Linine
-- 
View this message in context: http://www.nabble.com/getOutputStream-method-of-the-org.apache.jackrabbit.core.fs.mem.MemoryFileSystem-question-tp15653797p15798179.html
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: getOutputStream method of the org.apache.jackrabbit.core.fs.mem.MemoryFileSystem question

Posted by Stefan Guggisberg <st...@gmail.com>.
hi denis

On Sat, Feb 23, 2008 at 5:08 PM, Denis Linine <li...@freesurf.ch> wrote:
> Hello,
>
>  I had a look at the getOutputStream method of the
>  org.apache.jackrabbit.core.fs.mem.MemoryFileSystem class, its code is
>  presented below:
>
>  public OutputStream getOutputStream(String filePath) throws
>  FileSystemException
>  {
>         String folderPath = filePath;
>         if (filePath.lastIndexOf(FileSystem.SEPARATOR) > 0)
>         {
>             folderPath = filePath.substring(0, filePath.lastIndexOf("/"));
>         }
>         else
>         {
>             folderPath = "/";
>         }
>         assertIsFolder(folderPath);
>
>         final MemoryFile file = new MemoryFile();
>         entries.put(filePath, file);
>
>         return new FilterOutputStream(new ByteArrayOutputStream())
>         {
>             public void close() throws IOException
>             {
>                 out.close();
>                 file.setData(((ByteArrayOutputStream) out).toByteArray());
>             }
>         };
>     }
>
>  I might be wrong, but it seems that if the filePath passed points to an
>  existing folder and not to a file - the folder will be replaced with a
>  newly created file. Unfortunately, at the moment being I do not have JR
>  build environment set up to test practically whether this is really the
>  case. Might be some check whether the path passed really points to a
>  file should be added.

you're right. the implementation should check whether the specified
path points to a folder and throw an exception if that's the case.

could you please create a jira issue?

thanks!
stefan
>
>  Best regards
>  Denis Linine
>