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

Proposed by Carlos Jose Mazieri on 2015-07-19
Status: Merged
Approved by: Arto Jalkanen on 2015-08-21
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 on 2015-08-16
Arto Jalkanen 2015-07-19 Needs Information on 2015-08-07
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.
Arto Jalkanen (ajalkane) wrote :

See the comment

review: Needs Information

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 on 2015-08-15

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).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.cpp'
2--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.cpp 2015-05-20 17:15:29 +0000
3+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.cpp 2015-08-15 17:48:20 +0000
4@@ -42,11 +42,18 @@
5 #define DBG(none)
6 #endif
7
8+#define SHOW_ERRNO(path) if (errno != 0 && errno != ENOENT) \
9+ { \
10+ qWarning() << Q_FUNC_INFO << "path:" << path << "errno:" << errno << strerror(errno); \
11+ }
12+
13+#define URL_SLASHES_NUMBER_FOR_SHARES 3
14+
15 namespace
16 {
17- QByteArray s_user("guest");
18- QByteArray s_passwd;
19- QByteArray s_workGroup("WORKGROUP");
20+ QByteArray s_user("guest");
21+ QByteArray s_passwd;
22+ QByteArray s_workGroup("WORKGROUP");
23 }
24
25 //===============================================================================================
26@@ -250,7 +257,7 @@
27 }
28 if (fd == 0)
29 {
30- qWarning() << Q_FUNC_INFO << "errno:" << errno << smb_path;
31+ SHOW_ERRNO(smb_path);
32 }
33 return fd;
34 }
35@@ -281,7 +288,7 @@
36 }
37 if (fd == 0)
38 {
39- qWarning() << Q_FUNC_INFO << "errno:" << errno << smb_string;
40+ SHOW_ERRNO(smb_string);
41 }
42 return fd;
43 }
44@@ -315,8 +322,6 @@
45 /*!
46 * \brief SmbUtil::getStatInfo() It gets information about files and directories, similar to POSIX stat(2)
47 *
48- * It looks like smbclient brings no information for directories, it works only for files, in this case the caller
49- * must set valid information in the struct stat.
50 *
51 * The distintion between files and directories is made by \ref openDir() and \ref openFile(), as just one
52 * of them should open the \a smb_path.
53@@ -331,19 +336,18 @@
54 SmbUtil::getStatInfo(const QString &smb_path, struct stat* st)
55 {
56 Smb::Context context = createContext();
57- Q_ASSERT(context);
58- ::memset(st,0,sizeof(struct stat));
59+ Q_ASSERT(context);
60 StatReturn ret = StatInvalid;
61 int slashes = smb_path.count(QDir::separator());
62 Smb::FileHandler fd = 0;
63- // smb:// -> slahes=2 smb/workgroup -> slahes=2 smb://host/share -> slashes=3
64+ // smb:// -> slahes=2 smb://workgroup -> slahes=2 smb://host/share -> slashes=3=URL_SLASHES_NUMBER_FOR_SHARES
65 if ((fd=openDir(context, smb_path)))
66 {
67- if ((ret = guessDirType(context,fd)) == StatDir && slashes == 3)
68+ if ((ret = guessDirType(context,fd)) == StatDir && slashes == URL_SLASHES_NUMBER_FOR_SHARES)
69 {
70 ret = StatShare;
71 }
72- if (slashes > 2 && (ret == StatShare || ret == StatDir))
73+ if (slashes >= URL_SLASHES_NUMBER_FOR_SHARES && (ret == StatShare || ret == StatDir))
74 {
75 /* smbc_getFunctionFstatdir does not work
76 ret = static_cast<StatReturn>(::smbc_getFunctionFstatdir(context)(context,fd, st));
77@@ -353,7 +357,7 @@
78 {
79 ipUrl = smb_path;
80 }
81- (void)static_cast<StatReturn> (::smbc_getFunctionStat(context)(context,ipUrl.toLocal8Bit().constData(), st));
82+ (void)getStat(context,ipUrl, st);
83 }
84 }
85 else
86@@ -365,7 +369,7 @@
87 {
88 if ((fd = openFile(context,smb_path)))
89 {
90- ret = static_cast<StatReturn> (::smbc_getFunctionFstat(context)(context,fd, st));
91+ ret = getFstat(context,fd, st);
92 }
93 }
94 }
95@@ -376,10 +380,15 @@
96 }
97 else
98 {
99- qDebug() << Q_FUNC_INFO << "path:" << smb_path << "errno:" << errno << strerror(errno);
100+ SHOW_ERRNO(smb_path);
101 switch(errno)
102 {
103 case EACCES:
104+ //force shares to have Directory attribute
105+ if (slashes == URL_SLASHES_NUMBER_FOR_SHARES)
106+ {
107+ st->st_mode |= S_IFDIR;
108+ }
109 ret = StatNoAccess; //authentication should have failed
110 break;
111 case ENOENT:
112@@ -455,7 +464,8 @@
113 {
114 QStringList content;
115 Smb::Context context = createContext();
116- Q_ASSERT(context);
117+ Q_ASSERT(context);
118+ QStringList paths_Dot_or_DotDot;
119 Smb::FileHandler fd = openDir(context,smb_path);
120 if (fd)
121 {
122@@ -503,13 +513,18 @@
123 {
124 bool isDot = ::strcmp(".", cur_name) == 0;
125 bool isDotDot = ::strcmp("..", cur_name) == 0;
126- if( !((filters & QDir::NoDot) && isDot)
127- && !((filters & QDir::NoDotDot) && isDotDot) )
128- {
129- path = smb_path + QDir::separator() + cur_name;
130+ if( (!(filters & QDir::NoDot) && isDot)
131+ || (!(filters & QDir::NoDotDot) && isDotDot)
132+ || (!isDot && !isDotDot))
133+ {
134 if (!isDot && !isDotDot)
135 {
136 itemHasContent = true;
137+ path = smb_path + QDir::separator() + cur_name;
138+ }
139+ else // (isDot || isDotDot)
140+ {
141+ paths_Dot_or_DotDot.append(smb_path + QDir::separator() + cur_name);
142 }
143 }
144 }
145@@ -545,9 +560,13 @@
146 }//if (fd)
147 else
148 {
149- qDebug() << Q_FUNC_INFO << "could not open directory" << smb_path << "errno:" << errno;
150+ SHOW_ERRNO(smb_path);
151 }
152 deleteContext(context);
153+ if (paths_Dot_or_DotDot.count() > 0)
154+ {
155+ content += paths_Dot_or_DotDot;
156+ }
157 return content;
158 }
159
160@@ -656,9 +675,20 @@
161 Smb::FileHandler fd = openDir(context,smb_path);
162 if (fd == 0)
163 {
164- fd = openFile(context, smb_path);
165- }
166- if (fd)
167+ fd = openFile(context,smb_path);
168+ }
169+ if (fd == 0) // item does not exist neither dir nor file
170+ {
171+ //usually smb_path is a file that does not exist yet
172+ //so using the path
173+ int lastSlash = smb_path.lastIndexOf(QDir::separator());
174+ if (lastSlash != -1)
175+ {
176+ QString path (smb_path.mid(0,lastSlash));
177+ fd = openDir(context,path);
178+ }
179+ }
180+ if (fd != 0)
181 {
182 ret = static_cast<StatReturn> (::smbc_getFunctionFstatVFS(context)(context,fd, st));
183 closeHandle(context, fd);
184@@ -710,3 +740,32 @@
185 }
186 return host.toLower();
187 }
188+
189+
190+bool SmbUtil::changePermissions(Smb::Context context, const QString& smb_path, mode_t mode)
191+{
192+ int ret = ::smbc_getFunctionChmod(context)(context, smb_path.toLocal8Bit().constBegin(), mode);
193+ if (ret < 0)
194+ {
195+ SHOW_ERRNO(smb_path);
196+ }
197+ return ret == 0;
198+}
199+
200+
201+SmbUtil::StatReturn
202+SmbUtil::getFstat(Smb::Context context, Smb::FileHandler fd, struct stat* st)
203+{
204+ ::memset(st,0,sizeof(struct stat));
205+ int ret = ::smbc_getFunctionFstat(context)(context,fd, st);
206+ return static_cast<SmbUtil::StatReturn> (ret);
207+}
208+
209+
210+SmbUtil::StatReturn
211+SmbUtil::getStat(Smb::Context context, const QString& smb_path, struct stat* st)
212+{
213+ ::memset(st,0,sizeof(struct stat));
214+ int ret = ::smbc_getFunctionStat(context)(context,smb_path.toLocal8Bit().constData(), st);
215+ return static_cast<SmbUtil::StatReturn> (ret);
216+}
217
218=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.h'
219--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.h 2015-03-01 19:02:31 +0000
220+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbutil.h 2015-08-15 17:48:20 +0000
221@@ -87,13 +87,15 @@
222 Smb::FileHandler openDir(Smb::Context context, const QString& smb_string);
223 Smb::FileHandler openFile(Smb::Context context,const QString& smb_path,
224 int flags = O_RDONLY, mode_t mode = 0);
225+ bool changePermissions(Smb::Context context, const QString& smb_path, mode_t mode);
226 void closeHandle(Smb::Context context, Smb::FileHandler fd);
227 QStringList lisShares();
228 QStringList listContent(QString smb_path,
229 bool recursive = false,
230 QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot,
231 const QStringList& filterNames = QStringList());
232-
233+ StatReturn getFstat(Smb::Context context, Smb::FileHandler fd, struct stat* st);
234+ StatReturn getStat(Smb::Context context, const QString& smb_path, struct stat* st);
235
236 private:
237 StatReturn guessDirType(Smb::Context context, Smb::FileHandler fd);
238
239=== modified file 'src/plugin/folderlistmodel/smb/smblocationauthentication.cpp'
240--- src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-07-13 20:41:48 +0000
241+++ src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-08-15 17:48:20 +0000
242@@ -31,9 +31,13 @@
243 #endif
244
245
246-static QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
247-static QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
248-static void * m_instances[MAX_AUTH_INSTANCES];
249+namespace
250+{
251+ QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
252+ QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
253+ void * m_instances[MAX_AUTH_INSTANCES];
254+}
255+
256
257 SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
258 {

Subscribers

People subscribed via source and target branches