ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #03667
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11 into lp:ubuntu-filemanager-app
Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-10 as a prerequisite.
Commit message:
improved SmbUtil class, added method SmbUtil::changePermissions() that will be used by SmbLocationItemFile
Requested reviews:
Ubuntu File Manager Developers (ubuntu-filemanager-dev)
For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11/+merge/265210
Preparation to implement SmbLocationItemFile class
--
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.cpp 2015-05-20 17:15:29 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.cpp 2015-07-19 15:35:10 +0000
@@ -42,11 +42,18 @@
#define DBG(none)
#endif
+#define SHOW_ERRNO(path) if (errno != 0 && errno != ENOENT) \
+ { \
+ qWarning() << Q_FUNC_INFO << "path:" << path << "errno:" << errno << strerror(errno); \
+ }
+
+#define URL_SLASHES_NUMBER_FOR_SHARES 3
+
namespace
{
- QByteArray s_user("guest");
- QByteArray s_passwd;
- QByteArray s_workGroup("WORKGROUP");
+ QByteArray s_user("guest");
+ QByteArray s_passwd;
+ QByteArray s_workGroup("WORKGROUP");
}
//===============================================================================================
@@ -250,7 +257,7 @@
}
if (fd == 0)
{
- qWarning() << Q_FUNC_INFO << "errno:" << errno << smb_path;
+ SHOW_ERRNO(smb_path);
}
return fd;
}
@@ -281,7 +288,7 @@
}
if (fd == 0)
{
- qWarning() << Q_FUNC_INFO << "errno:" << errno << smb_string;
+ SHOW_ERRNO(smb_string);
}
return fd;
}
@@ -315,8 +322,6 @@
/*!
* \brief SmbUtil::getStatInfo() It gets information about files and directories, similar to POSIX stat(2)
*
- * It looks like smbclient brings no information for directories, it works only for files, in this case the caller
- * must set valid information in the struct stat.
*
* The distintion between files and directories is made by \ref openDir() and \ref openFile(), as just one
* of them should open the \a smb_path.
@@ -331,19 +336,18 @@
SmbUtil::getStatInfo(const QString &smb_path, struct stat* st)
{
Smb::Context context = createContext();
- Q_ASSERT(context);
- ::memset(st,0,sizeof(struct stat));
+ Q_ASSERT(context);
StatReturn ret = StatInvalid;
int slashes = smb_path.count(QDir::separator());
Smb::FileHandler fd = 0;
- // smb:// -> slahes=2 smb/workgroup -> slahes=2 smb://host/share -> slashes=3
+ // smb:// -> slahes=2 smb://workgroup -> slahes=2 smb://host/share -> slashes=3=URL_SLASHES_NUMBER_FOR_SHARES
if ((fd=openDir(context, smb_path)))
{
- if ((ret = guessDirType(context,fd)) == StatDir && slashes == 3)
+ if ((ret = guessDirType(context,fd)) == StatDir && slashes == URL_SLASHES_NUMBER_FOR_SHARES)
{
ret = StatShare;
}
- if (slashes > 2 && (ret == StatShare || ret == StatDir))
+ if (slashes >= URL_SLASHES_NUMBER_FOR_SHARES && (ret == StatShare || ret == StatDir))
{
/* smbc_getFunctionFstatdir does not work
ret = static_cast<StatReturn>(::smbc_getFunctionFstatdir(context)(context,fd, st));
@@ -353,7 +357,7 @@
{
ipUrl = smb_path;
}
- (void)static_cast<StatReturn> (::smbc_getFunctionStat(context)(context,ipUrl.toLocal8Bit().constData(), st));
+ (void)getStat(context,ipUrl, st);
}
}
else
@@ -365,7 +369,7 @@
{
if ((fd = openFile(context,smb_path)))
{
- ret = static_cast<StatReturn> (::smbc_getFunctionFstat(context)(context,fd, st));
+ ret = getFstat(context,fd, st);
}
}
}
@@ -376,10 +380,15 @@
}
else
{
- qDebug() << Q_FUNC_INFO << "path:" << smb_path << "errno:" << errno << strerror(errno);
+ SHOW_ERRNO(smb_path);
switch(errno)
{
case EACCES:
+ //force shares to have Directory attribute
+ if (slashes == URL_SLASHES_NUMBER_FOR_SHARES)
+ {
+ st->st_mode |= S_IFDIR;
+ }
ret = StatNoAccess; //authentication should have failed
break;
case ENOENT:
@@ -456,6 +465,8 @@
QStringList content;
Smb::Context context = createContext();
Q_ASSERT(context);
+ QString currentPathWithDot;
+ QString currentpathWithDotDot;
Smb::FileHandler fd = openDir(context,smb_path);
if (fd)
{
@@ -503,13 +514,19 @@
{
bool isDot = ::strcmp(".", cur_name) == 0;
bool isDotDot = ::strcmp("..", cur_name) == 0;
- if( !((filters & QDir::NoDot) && isDot)
- && !((filters & QDir::NoDotDot) && isDotDot) )
- {
- path = smb_path + QDir::separator() + cur_name;
+ if( (!(filters & QDir::NoDot) && isDot)
+ || (!(filters & QDir::NoDotDot) && isDotDot)
+ || (!isDot && !isDotDot))
+ {
if (!isDot && !isDotDot)
{
itemHasContent = true;
+ path = smb_path + QDir::separator() + cur_name;
+ }
+ else // (isDot || isDotDot)
+ {
+ if (isDot) { currentPathWithDot = smb_path + QDir::separator() + cur_name;}
+ else { currentpathWithDotDot = smb_path + QDir::separator() + cur_name;}
}
}
}
@@ -545,9 +562,17 @@
}//if (fd)
else
{
- qDebug() << Q_FUNC_INFO << "could not open directory" << smb_path << "errno:" << errno;
+ SHOW_ERRNO(smb_path);
}
deleteContext(context);
+ if (!currentPathWithDot.isEmpty())
+ {
+ content.append(currentPathWithDot);
+ }
+ if (!currentpathWithDotDot.isEmpty())
+ {
+ content.append(currentpathWithDotDot);
+ }
return content;
}
@@ -656,7 +681,18 @@
Smb::FileHandler fd = openDir(context,smb_path);
if (fd == 0)
{
- fd = openFile(context, smb_path);
+ openFile(context,smb_path);
+ }
+ if (fd == 0) // item does not exist neither dir nor file
+ {
+ //usually smb_path is a file that does not exist yet
+ //so using the path
+ int lastSlash = smb_path.lastIndexOf(QDir::separator());
+ if (lastSlash != -1)
+ {
+ QString path (smb_path.mid(0,lastSlash));
+ fd = openDir(context,path);
+ }
}
if (fd)
{
@@ -710,3 +746,32 @@
}
return host.toLower();
}
+
+
+bool SmbUtil::changePermissions(Smb::Context context, const QString& smb_path, mode_t mode)
+{
+ int ret = ::smbc_getFunctionChmod(context)(context, smb_path.toLocal8Bit().constBegin(), mode);
+ if (ret < 0)
+ {
+ SHOW_ERRNO(smb_path);
+ }
+ return ret == 0;
+}
+
+
+SmbUtil::StatReturn
+SmbUtil::getFstat(Smb::Context context, Smb::FileHandler fd, struct stat* st)
+{
+ ::memset(st,0,sizeof(struct stat));
+ int ret = ::smbc_getFunctionFstat(context)(context,fd, st);
+ return static_cast<SmbUtil::StatReturn> (ret);
+}
+
+
+SmbUtil::StatReturn
+SmbUtil::getStat(Smb::Context context, const QString& smb_path, struct stat* st)
+{
+ ::memset(st,0,sizeof(struct stat));
+ int ret = ::smbc_getFunctionStat(context)(context,smb_path.toLocal8Bit().constData(), st);
+ return static_cast<SmbUtil::StatReturn> (ret);
+}
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.h 2015-03-01 19:02:31 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.h 2015-07-19 15:35:10 +0000
@@ -87,13 +87,15 @@
Smb::FileHandler openDir(Smb::Context context, const QString& smb_string);
Smb::FileHandler openFile(Smb::Context context,const QString& smb_path,
int flags = O_RDONLY, mode_t mode = 0);
+ bool changePermissions(Smb::Context context, const QString& smb_path, mode_t mode);
void closeHandle(Smb::Context context, Smb::FileHandler fd);
QStringList lisShares();
QStringList listContent(QString smb_path,
bool recursive = false,
QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot,
const QStringList& filterNames = QStringList());
-
+ StatReturn getFstat(Smb::Context context, Smb::FileHandler fd, struct stat* st);
+ StatReturn getStat(Smb::Context context, const QString& smb_path, struct stat* st);
private:
StatReturn guessDirType(Smb::Context context, Smb::FileHandler fd);
=== modified file 'src/plugin/folderlistmodel/smb/smblocationauthentication.cpp'
--- src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-07-19 15:35:09 +0000
+++ src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-07-19 15:35:10 +0000
@@ -31,9 +31,13 @@
#endif
-static QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
-static QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
-static void * m_instances[MAX_AUTH_INSTANCES];
+namespace
+{
+ QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
+ QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
+ void * m_instances[MAX_AUTH_INSTANCES];
+}
+
SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
{
Follow ups