Port changes in #172 to python2
Michael Teo
3 years ago
428 | 428 | finally: |
429 | 429 | self.is_busy = False |
430 | 430 | |
431 | def resetFileAttributes(self, service_name, path_file_pattern, timeout = 30): | |
431 | def resetFileAttributes(self, service_name, path_file_pattern, file_attributes = ATTR_NORMAL, timeout = 30): | |
432 | 432 | """ |
433 | 433 | Reset file attributes of one or more regular files or folders. |
434 | 434 | It supports the use of wildcards in file names, allowing for unlocking of multiple files/folders in a single request. |
435 | 435 | This function is very helpful when deleting files/folders that are read-only. |
436 | Note: this function is currently only implemented for SMB2! Technically, it sets the FILE_ATTRIBUTE_NORMAL flag, therefore clearing all other flags. (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information) | |
436 | By default, it sets the ATTR_NORMAL flag, therefore clearing all other flags. | |
437 | (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information) | |
438 | ||
439 | Note: this function is currently only implemented for SMB2! | |
437 | 440 | |
438 | 441 | :param string/unicode service_name: Contains the name of the shared folder. |
439 | 442 | :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name. |
440 | 443 | Wildcards may be used in the filename component of the path. |
441 | 444 | If your path/filename contains non-English characters, you must pass in an unicode string. |
445 | :param int file_attributes: The desired file attributes to set. Defaults to `ATTR_NORMAL`. | |
442 | 446 | :return: None |
443 | 447 | """ |
444 | 448 | if not self.sock: |
453 | 457 | |
454 | 458 | self.is_busy = True |
455 | 459 | try: |
456 | self._resetFileAttributes(service_name, path_file_pattern, cb, eb, timeout = timeout) | |
460 | self._resetFileAttributes(service_name, path_file_pattern, cb, eb, file_attributes, timeout = timeout) | |
457 | 461 | while self.is_busy: |
458 | 462 | self._pollForNetBIOSPacket(timeout) |
459 | 463 | finally: |
1292 | 1292 | |
1293 | 1293 | sendCreate(tid) |
1294 | 1294 | |
1295 | def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
1295 | def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, file_attributes = ATTR_NORMAL, timeout = 30): | |
1296 | 1296 | if not self.has_authenticated: |
1297 | 1297 | raise NotReadyError('SMB connection not authenticated') |
1298 | 1298 | |
1340 | 1340 | additional_info = 0, |
1341 | 1341 | info_type = SMB2_INFO_FILE, |
1342 | 1342 | file_info_class = 4, # FileBasicInformation |
1343 | data = struct.pack('qqqqii',0,0,0,0,0x80,0))) # FILE_ATTRIBUTE_NORMAL | |
1343 | data = struct.pack('qqqqii',0,0,0,0,file_attributes,0))) | |
1344 | 1344 | # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4, [MS-FSCC]: 2.4.7, [MS-FSCC]: 2.6 |
1345 | 1345 | m.tid = tid |
1346 | 1346 | self._sendSMBMessage(m) |
2699 | 2699 | |
2700 | 2700 | sendDelete(tid) |
2701 | 2701 | |
2702 | def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
2702 | def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, file_attributes=ATTR_NORMAL, timeout = 30): | |
2703 | 2703 | raise NotReadyError('resetFileAttributes is not yet implemented for SMB1') |
2704 | 2704 | |
2705 | 2705 | def _createDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): |