26 #include <sys/types.h>
32 #include <tdelocale.h>
34 #include <tdemessagebox.h>
36 #include "tdeio/job.h"
37 #include "tdeio/chmodjob.h"
39 #include <kdirnotify_stub.h>
41 using namespace TDEIO;
44 int newOwner,
int newGroup,
45 bool recursive,
bool showProgressInfo )
46 :
TDEIO::
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, TQ_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, TQ_SIGNAL(entries(
TDEIO::Job *,
81 const TDEIO::UDSEntryList& )),
83 const TDEIO::UDSEntryList& )));
88 m_lstItems.removeFirst();
90 kdDebug(7007) <<
"ChmodJob::processList -> going to STATE_CHMODING" << endl;
92 state = STATE_CHMODING;
96 void ChmodJob::slotEntries(
TDEIO::Job*,
const TDEIO::UDSEntryList & list )
98 TDEIO::UDSEntryListConstIterator it = list.begin();
99 TDEIO::UDSEntryListConstIterator end = list.end();
100 for (; it != end; ++it) {
101 TDEIO::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 );
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 { TDEIO::Job::virtual_hook(
id, data ); }
258 #include "chmodjob.moc"
A KFileItem is a generic class to handle a file, local or remote.
bool isLink() const
Returns true if this item represents a link in the UNIX sense of a link.
const KURL & url() const
Returns the url of the file.
mode_t permissions() const
Returns the permissions of the file (stat.st_mode containing only permissions).
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.
ChmodJob(const KFileItemList &lstItems, int permissions, int mask, int newOwner, int newGroup, bool recursive, bool showProgressInfo)
Create new ChmodJobs using the TDEIO::chmod() function.
The base class for all jobs.
const TQString & errorText() const
Returns the error text if there has been an error.
void emitResult()
Utility function to emit the result signal, and suicide this job.
virtual void addSubjob(Job *job, bool inheritMetaData=true)
void addMetaData(const TQString &key, const TQString &value)
int error() const
Returns the error code, if there has been an error.
TQString queryMetaData(const TQString &key)
A ListJob is allows you to get the get the content of a directory.
A simple job (one url and one command).
A namespace for TDEIO globals.
TDEIO_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...
@ UDS_LINK_DEST
Name of the file where the link points to Allows to check for a symlink (don't use S_ISLNK !...
@ UDS_FILE_TYPE
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
@ UDS_ACCESS
Access permissions (part of the mode returned by stat)
@ UDS_NAME
Filename - as displayed in directory listings etc.
TDEIO_EXPORT ListJob * listRecursive(const KURL &url, bool showProgressInfo=true, bool includeHidden=true)
The same as the previous method, but recurses subdirectories.