26 #include <sys/types.h> 34 #include <kmessagebox.h> 37 #include "kio/chmodjob.h" 39 #include <kdirnotify_stub.h> 44 int newOwner,
int newGroup,
45 bool recursive,
bool showProgressInfo )
46 :
KIO::
Job( showProgressInfo ), state( STATE_LISTING ),
47 m_permissions( permissions ), m_mask( mask ),
48 m_newOwner( newOwner ), m_newGroup( newGroup ),
49 m_recursive( recursive ), m_lstItems( lstItems )
51 TQTimer::singleShot( 0,
this, TQT_SLOT(processList()) );
54 void ChmodJob::processList()
56 while ( !m_lstItems.isEmpty() )
63 info.url = item->
url();
65 info.permissions = ( m_permissions & m_mask ) | ( item->
permissions() & ~m_mask );
73 m_infos.prepend( info );
76 if ( item->
isDir() && m_recursive )
80 connect( listJob, TQT_SIGNAL(entries(
KIO::Job *,
81 const KIO::UDSEntryList& )),
83 const KIO::UDSEntryList& )));
88 m_lstItems.removeFirst();
90 kdDebug(7007) <<
"ChmodJob::processList -> going to STATE_CHMODING" << endl;
92 state = STATE_CHMODING;
96 void ChmodJob::slotEntries(
KIO::Job*,
const KIO::UDSEntryList & list )
98 KIO::UDSEntryListConstIterator it = list.begin();
99 KIO::UDSEntryListConstIterator end = list.end();
100 for (; it != end; ++it) {
101 KIO::UDSEntry::ConstIterator it2 = (*it).begin();
102 mode_t permissions = 0;
105 TQString relativePath;
106 for( ; it2 != (*it).end(); it2++ ) {
107 switch( (*it2).m_uds ) {
109 relativePath = (*it2).m_str;
112 isDir = S_ISDIR((*it2).m_long);
115 isLink = !(*it2).m_str.isEmpty();
118 permissions = (mode_t)((*it2).m_long);
124 if ( !isLink && relativePath != TQString::fromLatin1(
"..") )
127 info.url = m_lstItems.first()->url();
128 info.url.addPath( relativePath );
135 int newPerms = m_permissions & mask;
136 if ( (newPerms & 0111) && !(permissions & 0111) )
139 if ( newPerms & 02000 )
145 info.permissions = ( m_permissions & mask ) | ( permissions & ~mask );
155 m_infos.prepend( info );
160 void ChmodJob::chmodNextFile()
162 if ( !m_infos.isEmpty() )
164 ChmodInfo info = m_infos.first();
165 m_infos.remove( m_infos.begin() );
168 if ( info.url.isLocalFile() && ( m_newOwner != -1 || m_newGroup != -1 ) )
170 TQString path = info.url.path();
171 if ( chown( TQFile::encodeName(path), m_newOwner, m_newGroup ) != 0 )
173 int answer = KMessageBox::warningContinueCancel( 0, i18n(
"<qt>Could not modify the ownership of file <b>%1</b>. You have insufficient access to the file to perform the change.</qt>" ).arg(path), TQString::null, i18n(
"&Skip File") );
174 if (answer == KMessageBox::Cancel)
176 m_error = ERR_USER_CANCELED;
183 kdDebug(7007) <<
"ChmodJob::chmodNextFile chmod'ing " << info.url.prettyURL()
184 <<
" to " << TQString::number(info.permissions,8) << endl;
188 const TQString defaultAclString =
queryMetaData(
"DEFAULT_ACL_STRING" );
189 if ( !aclString.isEmpty() )
191 if ( !defaultAclString.isEmpty() )
192 job->
addMetaData(
"DEFAULT_ACL_STRING", defaultAclString );
200 void ChmodJob::slotResult(
KIO::Job * job )
204 m_error = job->
error();
214 m_lstItems.removeFirst();
215 kdDebug(7007) <<
"ChmodJob::slotResult -> processList" << endl;
220 kdDebug(7007) <<
"ChmodJob::slotResult -> chmodNextFile" << endl;
231 TQString owner, TQString group,
232 bool recursive,
bool showProgressInfo )
234 uid_t newOwnerID = (uid_t)-1;
235 if ( !owner.isEmpty() )
237 struct passwd* pw = getpwnam(TQFile::encodeName(owner));
239 kdError(250) <<
" ERROR: No user " << owner << endl;
241 newOwnerID = pw->pw_uid;
243 gid_t newGroupID = (gid_t)-1;
244 if ( !group.isEmpty() )
246 struct group* g = getgrnam(TQFile::encodeName(group));
248 kdError(250) <<
" ERROR: No group " << group << endl;
250 newGroupID = g->gr_gid;
252 return new ChmodJob( lstItems, permissions, mask, newOwnerID, newGroupID, recursive, showProgressInfo );
255 void ChmodJob::virtual_hook(
int id,
void* data )
256 { KIO::Job::virtual_hook(
id, data ); }
258 #include "chmodjob.moc" const KURL & url() const
Returns the url of the file.
A namespace for KIO globals.
const TQString & errorText() const
Returns the error text if there has been an error.
A ListJob is allows you to get the get the content of a directory.
TQString queryMetaData(const TQString &key)
Query meta data received from the slave.
mode_t permissions() const
Returns the permissions of the file (stat.st_mode containing only permissions).
virtual void addSubjob(Job *job, bool inheritMetaData=true)
Add a job that has to be finished before a result is emitted.
bool isDir() const
Returns true if this item represents a directory.
This job changes permissions on a list of files or directories, optionally in a recursive manner...
KIO_EXPORT ChmodJob * chmod(const KFileItemList &lstItems, int permissions, int mask, TQString newOwner, TQString newGroup, bool recursive, bool showProgressInfo=true)
Creates a job that changes permissions/ownership on several files or directories, optionally recursiv...
Filename - as displayed in directory listings etc.
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
void addMetaData(const TQString &key, const TQString &value)
Add key/value pair to the meta data that is sent to the slave.
void emitResult()
Utility function to emit the result signal, and suicide this job.
Name of the file where the link points to Allows to check for a symlink (don't use S_ISLNK !) ...
Access permissions (part of the mode returned by stat)
ChmodJob(const KFileItemList &lstItems, int permissions, int mask, int newOwner, int newGroup, bool recursive, bool showProgressInfo)
Create new ChmodJobs using the KIO::chmod() function.
bool isLink() const
Returns true if this item represents a link in the UNIX sense of a link.
KIO_EXPORT ListJob * listRecursive(const KURL &url, bool showProgressInfo=true, bool includeHidden=true)
The same as the previous method, but recurses subdirectories.
The base class for all jobs.
A KFileItem is a generic class to handle a file, local or remote.
int error() const
Returns the error code, if there has been an error.
A simple job (one url and one command).