Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 443
Merged at revision: 448
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-10
Diff against target: 258 lines (+93/-28)
3 files modified
src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.cpp (+83/-24)
src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.h (+3/-1)
src/plugin/folderlistmodel/smb/smblocationauthentication.cpp (+7/-3)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Arto Jalkanen Needs Information
Review via email: mp+265210@code.launchpad.net

Commit message

improved SmbUtil class, added method SmbUtil::changePermissions() that will be used by SmbLocationItemFile

Description of the change

Preparation to implement SmbLocationItemFile class

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

See the comment

review: Needs Information
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

About the comment:

   166 if (fd == 0)
   167 {
   168 - fd = openFile(context, smb_path);
   169 + openFile(context,smb_path);

It is really a mistake, the function still works most of the times due to next "if" that still tries to get a valid descriptor from the parent directory.

That will be fixed.

Other comment:

   153 + if (!currentPathWithDot.isEmpty())
   154 + {
   155 + content.append(currentPathWithDot);
   156 + }
   157 + if (!currentpathWithDotDot.isEmpty())
   158 + {
   159 + content.append(currentpathWithDotDot);
   160 + }

it will be improved.

Thanks.

443. By Carlos Jose Mazieri

Fixed SmbUtil::getStatvfsInfo() where it misses a file descriptor to assign in the call SmbUtil::openFile().
Improved SmbUtil::listContent() about getting paths with '." (dot) and paths with '..' (dotdot).

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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-08-15 17:48:20 +0000
@@ -42,11 +42,18 @@
42#define DBG(none)42#define DBG(none)
43#endif43#endif
4444
45#define SHOW_ERRNO(path) if (errno != 0 && errno != ENOENT) \
46 { \
47 qWarning() << Q_FUNC_INFO << "path:" << path << "errno:" << errno << strerror(errno); \
48 }
49
50#define URL_SLASHES_NUMBER_FOR_SHARES 3
51
45namespace52namespace
46{53{
47 QByteArray s_user("guest");54 QByteArray s_user("guest");
48 QByteArray s_passwd;55 QByteArray s_passwd;
49 QByteArray s_workGroup("WORKGROUP");56 QByteArray s_workGroup("WORKGROUP");
50}57}
5158
52//===============================================================================================59//===============================================================================================
@@ -250,7 +257,7 @@
250 }257 }
251 if (fd == 0)258 if (fd == 0)
252 {259 {
253 qWarning() << Q_FUNC_INFO << "errno:" << errno << smb_path;260 SHOW_ERRNO(smb_path);
254 }261 }
255 return fd;262 return fd;
256}263}
@@ -281,7 +288,7 @@
281 }288 }
282 if (fd == 0)289 if (fd == 0)
283 {290 {
284 qWarning() << Q_FUNC_INFO << "errno:" << errno << smb_string;291 SHOW_ERRNO(smb_string);
285 }292 }
286 return fd;293 return fd;
287}294}
@@ -315,8 +322,6 @@
315/*!322/*!
316 * \brief SmbUtil::getStatInfo() It gets information about files and directories, similar to POSIX stat(2)323 * \brief SmbUtil::getStatInfo() It gets information about files and directories, similar to POSIX stat(2)
317 *324 *
318 * It looks like smbclient brings no information for directories, it works only for files, in this case the caller
319 * must set valid information in the struct stat.
320 *325 *
321 * The distintion between files and directories is made by \ref openDir() and \ref openFile(), as just one326 * The distintion between files and directories is made by \ref openDir() and \ref openFile(), as just one
322 * of them should open the \a smb_path.327 * of them should open the \a smb_path.
@@ -331,19 +336,18 @@
331SmbUtil::getStatInfo(const QString &smb_path, struct stat* st)336SmbUtil::getStatInfo(const QString &smb_path, struct stat* st)
332{ 337{
333 Smb::Context context = createContext(); 338 Smb::Context context = createContext();
334 Q_ASSERT(context);339 Q_ASSERT(context);
335 ::memset(st,0,sizeof(struct stat));
336 StatReturn ret = StatInvalid;340 StatReturn ret = StatInvalid;
337 int slashes = smb_path.count(QDir::separator());341 int slashes = smb_path.count(QDir::separator());
338 Smb::FileHandler fd = 0;342 Smb::FileHandler fd = 0;
339 // smb:// -> slahes=2 smb/workgroup -> slahes=2 smb://host/share -> slashes=3343 // smb:// -> slahes=2 smb://workgroup -> slahes=2 smb://host/share -> slashes=3=URL_SLASHES_NUMBER_FOR_SHARES
340 if ((fd=openDir(context, smb_path)))344 if ((fd=openDir(context, smb_path)))
341 { 345 {
342 if ((ret = guessDirType(context,fd)) == StatDir && slashes == 3)346 if ((ret = guessDirType(context,fd)) == StatDir && slashes == URL_SLASHES_NUMBER_FOR_SHARES)
343 {347 {
344 ret = StatShare;348 ret = StatShare;
345 }349 }
346 if (slashes > 2 && (ret == StatShare || ret == StatDir))350 if (slashes >= URL_SLASHES_NUMBER_FOR_SHARES && (ret == StatShare || ret == StatDir))
347 {351 {
348 /* smbc_getFunctionFstatdir does not work352 /* smbc_getFunctionFstatdir does not work
349 ret = static_cast<StatReturn>(::smbc_getFunctionFstatdir(context)(context,fd, st));353 ret = static_cast<StatReturn>(::smbc_getFunctionFstatdir(context)(context,fd, st));
@@ -353,7 +357,7 @@
353 {357 {
354 ipUrl = smb_path;358 ipUrl = smb_path;
355 }359 }
356 (void)static_cast<StatReturn> (::smbc_getFunctionStat(context)(context,ipUrl.toLocal8Bit().constData(), st));360 (void)getStat(context,ipUrl, st);
357 }361 }
358 }362 }
359 else363 else
@@ -365,7 +369,7 @@
365 {369 {
366 if ((fd = openFile(context,smb_path)))370 if ((fd = openFile(context,smb_path)))
367 {371 {
368 ret = static_cast<StatReturn> (::smbc_getFunctionFstat(context)(context,fd, st));372 ret = getFstat(context,fd, st);
369 }373 }
370 }374 }
371 }375 }
@@ -376,10 +380,15 @@
376 }380 }
377 else381 else
378 {382 {
379 qDebug() << Q_FUNC_INFO << "path:" << smb_path << "errno:" << errno << strerror(errno);383 SHOW_ERRNO(smb_path);
380 switch(errno)384 switch(errno)
381 {385 {
382 case EACCES:386 case EACCES:
387 //force shares to have Directory attribute
388 if (slashes == URL_SLASHES_NUMBER_FOR_SHARES)
389 {
390 st->st_mode |= S_IFDIR;
391 }
383 ret = StatNoAccess; //authentication should have failed392 ret = StatNoAccess; //authentication should have failed
384 break;393 break;
385 case ENOENT:394 case ENOENT:
@@ -455,7 +464,8 @@
455{464{
456 QStringList content;465 QStringList content;
457 Smb::Context context = createContext();466 Smb::Context context = createContext();
458 Q_ASSERT(context);467 Q_ASSERT(context);
468 QStringList paths_Dot_or_DotDot;
459 Smb::FileHandler fd = openDir(context,smb_path);469 Smb::FileHandler fd = openDir(context,smb_path);
460 if (fd)470 if (fd)
461 {471 {
@@ -503,13 +513,18 @@
503 {513 {
504 bool isDot = ::strcmp(".", cur_name) == 0;514 bool isDot = ::strcmp(".", cur_name) == 0;
505 bool isDotDot = ::strcmp("..", cur_name) == 0;515 bool isDotDot = ::strcmp("..", cur_name) == 0;
506 if( !((filters & QDir::NoDot) && isDot)516 if( (!(filters & QDir::NoDot) && isDot)
507 && !((filters & QDir::NoDotDot) && isDotDot) )517 || (!(filters & QDir::NoDotDot) && isDotDot)
508 {518 || (!isDot && !isDotDot))
509 path = smb_path + QDir::separator() + cur_name;519 {
510 if (!isDot && !isDotDot)520 if (!isDot && !isDotDot)
511 {521 {
512 itemHasContent = true;522 itemHasContent = true;
523 path = smb_path + QDir::separator() + cur_name;
524 }
525 else // (isDot || isDotDot)
526 {
527 paths_Dot_or_DotDot.append(smb_path + QDir::separator() + cur_name);
513 }528 }
514 }529 }
515 }530 }
@@ -545,9 +560,13 @@
545 }//if (fd)560 }//if (fd)
546 else561 else
547 {562 {
548 qDebug() << Q_FUNC_INFO << "could not open directory" << smb_path << "errno:" << errno;563 SHOW_ERRNO(smb_path);
549 }564 }
550 deleteContext(context);565 deleteContext(context);
566 if (paths_Dot_or_DotDot.count() > 0)
567 {
568 content += paths_Dot_or_DotDot;
569 }
551 return content;570 return content;
552}571}
553572
@@ -656,9 +675,20 @@
656 Smb::FileHandler fd = openDir(context,smb_path);675 Smb::FileHandler fd = openDir(context,smb_path);
657 if (fd == 0)676 if (fd == 0)
658 {677 {
659 fd = openFile(context, smb_path);678 fd = openFile(context,smb_path);
660 }679 }
661 if (fd)680 if (fd == 0) // item does not exist neither dir nor file
681 {
682 //usually smb_path is a file that does not exist yet
683 //so using the path
684 int lastSlash = smb_path.lastIndexOf(QDir::separator());
685 if (lastSlash != -1)
686 {
687 QString path (smb_path.mid(0,lastSlash));
688 fd = openDir(context,path);
689 }
690 }
691 if (fd != 0)
662 {692 {
663 ret = static_cast<StatReturn> (::smbc_getFunctionFstatVFS(context)(context,fd, st));693 ret = static_cast<StatReturn> (::smbc_getFunctionFstatVFS(context)(context,fd, st));
664 closeHandle(context, fd);694 closeHandle(context, fd);
@@ -710,3 +740,32 @@
710 }740 }
711 return host.toLower();741 return host.toLower();
712}742}
743
744
745bool SmbUtil::changePermissions(Smb::Context context, const QString& smb_path, mode_t mode)
746{
747 int ret = ::smbc_getFunctionChmod(context)(context, smb_path.toLocal8Bit().constBegin(), mode);
748 if (ret < 0)
749 {
750 SHOW_ERRNO(smb_path);
751 }
752 return ret == 0;
753}
754
755
756SmbUtil::StatReturn
757SmbUtil::getFstat(Smb::Context context, Smb::FileHandler fd, struct stat* st)
758{
759 ::memset(st,0,sizeof(struct stat));
760 int ret = ::smbc_getFunctionFstat(context)(context,fd, st);
761 return static_cast<SmbUtil::StatReturn> (ret);
762}
763
764
765SmbUtil::StatReturn
766SmbUtil::getStat(Smb::Context context, const QString& smb_path, struct stat* st)
767{
768 ::memset(st,0,sizeof(struct stat));
769 int ret = ::smbc_getFunctionStat(context)(context,smb_path.toLocal8Bit().constData(), st);
770 return static_cast<SmbUtil::StatReturn> (ret);
771}
713772
=== 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-08-15 17:48:20 +0000
@@ -87,13 +87,15 @@
87 Smb::FileHandler openDir(Smb::Context context, const QString& smb_string);87 Smb::FileHandler openDir(Smb::Context context, const QString& smb_string);
88 Smb::FileHandler openFile(Smb::Context context,const QString& smb_path,88 Smb::FileHandler openFile(Smb::Context context,const QString& smb_path,
89 int flags = O_RDONLY, mode_t mode = 0);89 int flags = O_RDONLY, mode_t mode = 0);
90 bool changePermissions(Smb::Context context, const QString& smb_path, mode_t mode);
90 void closeHandle(Smb::Context context, Smb::FileHandler fd);91 void closeHandle(Smb::Context context, Smb::FileHandler fd);
91 QStringList lisShares();92 QStringList lisShares();
92 QStringList listContent(QString smb_path,93 QStringList listContent(QString smb_path,
93 bool recursive = false,94 bool recursive = false,
94 QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot,95 QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot,
95 const QStringList& filterNames = QStringList());96 const QStringList& filterNames = QStringList());
9697 StatReturn getFstat(Smb::Context context, Smb::FileHandler fd, struct stat* st);
98 StatReturn getStat(Smb::Context context, const QString& smb_path, struct stat* st);
9799
98private: 100private:
99 StatReturn guessDirType(Smb::Context context, Smb::FileHandler fd);101 StatReturn guessDirType(Smb::Context context, Smb::FileHandler fd);
100102
=== modified file 'src/plugin/folderlistmodel/smb/smblocationauthentication.cpp'
--- src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-08-15 17:48:20 +0000
@@ -31,9 +31,13 @@
31#endif31#endif
3232
3333
34static QByteArray m_AuthUser[MAX_AUTH_INSTANCES];34namespace
35static QByteArray m_AuthPass[MAX_AUTH_INSTANCES];35{
36static void * m_instances[MAX_AUTH_INSTANCES];36 QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
37 QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
38 void * m_instances[MAX_AUTH_INSTANCES];
39}
40
3741
38SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)42SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
39{43{

Subscribers

People subscribed via source and target branches