Issue 126870

Summary: Bug: FTP UCP: getPropertyValues command for non-directory files for Size, DateCreated etc not set for files hosted on Windows server
Product: General Reporter: John Dougrez-Lewis <jlewis>
Component: codeAssignee: AOO issues mailing list <issues>
Status: UNCONFIRMED --- QA Contact:
Severity: Normal    
Priority: P5 (lowest) CC: oooforum
Version: 4.1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows, all   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---

Description John Dougrez-Lewis 2016-03-12 13:01:09 UTC
in file: ./ucp/ftp/ftpcontent.cxx
in function: getPropertyValues()

The FTPDirEntry::m_nmode value for a non-Directory (i.e. a plain ordinary file) is left as INETCOREFTP_FILEMODE_UNKNOWN (0) when the FTPDirEntry structure is populated from parsing a listing from a file on a Windowe FTP server.


The effect of this is as follows:

Any property queried in the getPropertyValues() function listed in the if() {...} block below is left at a default value, meaning that the value retrieved from parsing cannot be returned.

       else if(aDirEntry.m_nMode != INETCOREFTP_FILEMODE_UNKNOWN) {
            if(Name.compareToAscii("ContentType") == 0)
                xRow->appendString(seqProp[i],
                                   aDirEntry.m_nMode&INETCOREFTP_FILEMODE_ISDIR
                                   ? FTP_FOLDER
                                   : FTP_FILE );
            else if(Name.compareToAscii("IsReadOnly") == 0)
                xRow->appendBoolean(seqProp[i],
                                    aDirEntry.m_nMode
                                    & INETCOREFTP_FILEMODE_WRITE
                                    ? 0
                                    : 1 );
            else if(Name.compareToAscii("IsDocument") == 0)
                xRow->appendBoolean(seqProp[i],
                                    ! sal_Bool(aDirEntry.m_nMode &
                                               INETCOREFTP_FILEMODE_ISDIR));
            else if(Name.compareToAscii("IsFolder") == 0)
                xRow->appendBoolean(seqProp[i],
                                    sal_Bool(aDirEntry.m_nMode &
                                             INETCOREFTP_FILEMODE_ISDIR));
            else if(Name.compareToAscii("Size") == 0)
                xRow->appendLong(seqProp[i],
                                 aDirEntry.m_nSize);
            else if(Name.compareToAscii("DateCreated") == 0)
                xRow->appendTimestamp(seqProp[i],
                                      aDirEntry.m_aDate);
            else
                xRow->appendVoid(seqProp[i]);
        } else

The code could do with something having a bit flag (e.g. "INETCOREFTP_FILEMODE_ISDIR") to indicate teh file is valid in this case (or some other test/indication that the file is valid) so as to avoid the failure to return the valid values from the requested properties (Size, DateCreated etc).
Comment 1 John Dougrez-Lewis 2016-03-12 13:53:45 UTC
// e.g. something along these lines:

// file: .\ucb\source\ucp\ftp\ftpcontent.cxx

static bool isValidFile(const FTPDirentry& aDirEntry)
{
	if (aDirEntry.m_nMode != INETCOREFTP_FILEMODE_UNKNOWN)
		return(true);

	if (aDirEntry.m_nSize>0)
		return(true);

	if (aDirEntry.m_aDate.Year!=0)
		return(true);

	return(false);
}


Reference< XRow > FTPContent::getPropertyValues(
    const Sequence< Property >& seqProp,
    const Reference<XCommandEnvironment>& /*environment*/
)
{
    rtl::Reference<ucbhelper::PropertyValueSet> xRow =
        new ucbhelper::PropertyValueSet(m_xSMgr);

    FTPDirentry aDirEntry = m_aFTPURL.direntry();

    for(sal_Int32 i = 0; i < seqProp.getLength(); ++i) {
        const rtl::OUString& Name = seqProp[i].Name;
        if(Name.compareToAscii("Title") == 0)
            xRow->appendString(seqProp[i],aDirEntry.m_aName);
        else if(Name.compareToAscii("CreatableContentsInfo") == 0)
            xRow->appendObject(seqProp[i],
                               makeAny(queryCreatableContentsInfo()));
//!!!!
//		else if (aDirEntry.m_nMode != INETCOREFTP_FILEMODE_UNKNOWN) {
		else if (isValidFile(aDirEntry)) {
//!!!!

			if (Name.compareToAscii("ContentType") == 0)
                xRow->appendString(seqProp[i],
                                   aDirEntry.m_nMode&INETCOREFTP_FILEMODE_ISDIR
                                   ? FTP_FOLDER
                                   : FTP_FILE );
            else if(Name.compareToAscii("IsReadOnly") == 0)
                xRow->appendBoolean(seqProp[i],
                                    aDirEntry.m_nMode
                                    & INETCOREFTP_FILEMODE_WRITE
                                    ? 0
                                    : 1 );
            else if(Name.compareToAscii("IsDocument") == 0)
                xRow->appendBoolean(seqProp[i],
                                    ! sal_Bool(aDirEntry.m_nMode &
                                               INETCOREFTP_FILEMODE_ISDIR));
            else if(Name.compareToAscii("IsFolder") == 0)
                xRow->appendBoolean(seqProp[i],
                                    sal_Bool(aDirEntry.m_nMode &
                                             INETCOREFTP_FILEMODE_ISDIR));
            else if(Name.compareToAscii("Size") == 0)
                xRow->appendLong(seqProp[i],
                                 aDirEntry.m_nSize);
            else if(Name.compareToAscii("DateCreated") == 0)
                xRow->appendTimestamp(seqProp[i],
                                      aDirEntry.m_aDate);
            else
                xRow->appendVoid(seqProp[i]);
        } else
            xRow->appendVoid(seqProp[i]);
    }

    return Reference<XRow>(xRow.get());
}
Comment 2 John Dougrez-Lewis 2016-03-13 08:31:24 UTC
Here is another bug in the same category:

Deleting non-Folder simple file on Windows FTP Server:

File: ./ucb/source/ucp/ftp/ftpurl.cxx
function: void FTPURL::del() const

Replace exist code:

     else if (aDirentry.m_nMode != INETCOREFTP_FILEMODE_UNKNOWN)
	dele = rtl::OString("DELE ") + dele;
     else
        return;

with:
    else
	dele = rtl::OString("DELE ") + dele;

Otherwise a [Windows] file that is not a directory and has no other [aDirentry.m_nMode] attributes set fails to be deleted.
Comment 3 oooforum (fr) 2016-03-14 07:52:26 UTC
Maybe you could propose a patch?
Dev team will be happy :-)