Chris Muller uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-cmm.60.mcz ==================== Summary ==================== Name: Network-cmm.60 Author: cmm Time: 15 February 2010, 4:18:50.118 pm UUID: ce011288-d05c-4597-9aae-ad7ca3197fcd Ancestors: Network-dtl.59 - Updates to work with new refactored DirectoryEntry in the Files package. - Important fixes ensure ServerDirectory operations are performed on the correct directory! - By synchronizing some of the API, ServerDirectory is now a little more transparently-interchangeable with FileDirectory. =============== Diff against Network-dtl.59 =============== Item was changed: ----- Method: ServerDirectory>>createDirectory: (in category 'file directory') ----- createDirectory: localName "Create a new sub directory within the current one" self isTypeFile ifTrue: [ ^FileDirectory createDirectory: localName ]. client := self openFTPClient. + self switchDirectory. [client makeDirectory: localName] ensure: [self quit]. ! Item was changed: ----- Method: PRServerDirectory>>parseLine: (in category 'private') ----- parseLine: aString "private - parse a line from a server response" | tokens | tokens := aString findTokens: '|'. "" ^ tokens first = 'D' + ifTrue: + [ DirectoryEntryDirectory + directory: self - ifTrue: ["" - DirectoryEntry name: tokens second creationTime: 0 modificationTime: 0 + fileSize: 0 ] + ifFalse: + [ DirectoryEntryFile + directory: self - isDirectory: true - fileSize: 0] - ifFalse: ["" - DirectoryEntry name: tokens second creationTime: tokens third asInteger modificationTime: tokens fourth asInteger + fileSize: tokens fifth asInteger ]! - isDirectory: false - fileSize: tokens fifth asInteger]! Item was changed: ----- Method: ServerDirectory>>deleteFileNamed: (in category 'file directory') ----- deleteFileNamed: fullName "Detete a remote file. fullName is directory path, and does include name of the server. Or it can just be a fileName." | file | file := self asServerFileNamed: fullName. file isTypeFile ifTrue: [ ^ (FileDirectory forFileName: (file fileNameRelativeTo: self)) deleteFileNamed: file fileName ]. client := self openFTPClient. + [ self switchDirectory. + client deleteFileNamed: fullName] - [client deleteFileNamed: fullName] ensure: [self quit]. ! Item was added: + ----- Method: ServerDirectory>>deleteLocalFiles (in category 'file directory') ----- + deleteLocalFiles + "Delete the local files in this directory." + self switchDirectory. + self fileNames do:[:fn| self deleteFileNamed: fn ifAbsent: [(CannotDeleteFileException new + messageText: 'Could not delete the old version of file ' , (self fullNameFor: fn)) signal]]! Item was added: + ----- Method: ServerDirectory>>recursiveDelete (in category 'file-operations') ----- + recursiveDelete + "Delete the this directory, recursing down its tree." + self directoryNames + do: [:dn | (self directoryNamed: dn) recursiveDelete]. + self deleteLocalFiles. + "should really be some exception handling for directory deletion, but no + support for it yet" + self containingDirectory deleteDirectory: self localName! Item was changed: ----- Method: ServerDirectory>>exists (in category 'file directory') ----- exists "It is difficult to tell if a directory exists. This is ugly, but it works for writable directories. http: will fall back on ftp for this" | probe | self isTypeFile ifTrue: [ self entries size > 0 ifTrue: [^ true]. probe := self newFileNamed: 'withNoName23'. probe ifNotNil: [ probe close. probe directory deleteFileNamed: probe localName]. ^probe notNil]. ^ [client := self openFTPClient. + [self switchDirectory] - [client pwd] ensure: [self quit]. true] on: Error do: [:ex | false]! Item was changed: ----- Method: ServerDirectory class>>parseFTPEntry: (in category 'misc') ----- parseFTPEntry: ftpEntry | tokens longy dateInSeconds thisYear thisMonth | thisYear := Date today year. thisMonth := Date today monthIndex. + tokens := ftpEntry findTokens: ' '. - tokens := ftpEntry findTokens: ' '. - tokens size = 8 ifTrue: [((tokens at: 6) size ~= 3 and: [(tokens at: 5) size = 3]) ifTrue: ["Fix for case that group is blank (relies on month being 3 chars)" tokens := tokens copyReplaceFrom: 4 to: 3 with: {'blank'}]]. tokens size >= 9 ifFalse:[^nil]. ((tokens at: 6) size ~= 3 and: [(tokens at: 5) size = 3]) ifTrue: ["Fix for case that group is blank (relies on month being 3 chars)" tokens := tokens copyReplaceFrom: 4 to: 3 with: {'blank'}]. tokens size > 9 ifTrue: + [ "cmm: this approach fails for filenames containing two spaces in a row." + longy := tokens at: 9. - [longy := tokens at: 9. 10 to: tokens size do: [:i | longy := longy , ' ' , (tokens at: i)]. tokens at: 9 put: longy]. dateInSeconds := self secondsForDay: (tokens at: 7) month: (tokens at: 6) yearOrTime: (tokens at: 8) thisMonth: thisMonth + thisYear: thisYear. + ^DirectoryEntry name: (tokens at: 9) "file name" - thisYear: thisYear. - - ^DirectoryEntry name: (tokens last) "file name" creationTime: dateInSeconds "creation date" modificationTime: dateInSeconds "modification time" + isDirectory: ((tokens first first) = $d or: [tokens first first =$l]) "is-a-directory flag" - isDirectory:( (tokens first first) = $d or: [tokens first first =$l]) "is-a-directory flag" fileSize: tokens fifth asNumber "file size" ! Item was added: + ----- Method: ServerDirectory>>switchDirectory (in category 'initialize') ----- + switchDirectory + client changeDirectoryTo: directory! Item was changed: ----- Method: ServerDirectory>>deleteDirectory: (in category 'file directory') ----- deleteDirectory: localName "Delete the sub directory within the current one. Call needs to ask user to confirm." self isTypeFile ifTrue: [ ^FileDirectory deleteFileNamed: localName ]. "Is this the right command???" client := self openFTPClient. + [ self switchDirectory. + client deleteDirectory: localName] - [client deleteDirectory: localName] ensure: [self quit]. ! Item was added: + ----- Method: ServerDirectory>>entryAt: (in category 'file directory') ----- + entryAt: fileName + "find the entry with local name fileName" + ^ self + entryAt: fileName + ifAbsent: [ self error: 'file not in directory: ' , fileName ]! Item was changed: ----- Method: ServerDirectory>>getDirectory (in category 'up/download') ----- getDirectory "Return a stream with a listing of the current server directory. (Later -- Use a proxy server if one has been registered.)" | listing | client := self openFTPClient. + listing := + [ self switchDirectory. + client getDirectory] + ensure: [self quit]. - listing := [client getDirectory] - ensure: [self quit]. ^ReadStream on: listing! Item was changed: ----- Method: ServerDirectory>>getFileNamed:into:httpRequest: (in category 'up/download') ----- getFileNamed: fileNameOnServer into: dataStream httpRequest: requestString "Just FTP a file from a server. Return a stream. (Later -- Use a proxy server if one has been registered.)" | resp | self isTypeFile ifTrue: [ dataStream nextPutAll: (resp := FileStream oldFileNamed: server,(self serverDelimiter asString), self bareDirectory, (self serverDelimiter asString), fileNameOnServer) contentsOfEntireFile. dataStream dataIsValid. ^ resp]. self isTypeHTTP ifTrue: [ resp := HTTPSocket httpGet: (self fullNameFor: fileNameOnServer) args: nil accept: 'application/octet-stream' request: requestString. resp isString ifTrue: [^ dataStream]. "error, no data" dataStream copyFrom: resp. dataStream dataIsValid. ^ dataStream]. client := self openFTPClient. "Open passive. Do everything up to RETR or STOR" + [self switchDirectory. + client getFileNamed: fileNameOnServer into: dataStream] - [client getFileNamed: fileNameOnServer into: dataStream] ensure: [self quit]. dataStream dataIsValid. ! Item was changed: ----- Method: ServerDirectory>>putFile:named: (in category 'up/download') ----- putFile: fileStream named: fileNameOnServer "Just FTP a local fileStream to the server. (Later -- Use a proxy server if one has been registered.)" client := self openFTPClient. client binary. + [self switchDirectory. + client putFileStreamContents: fileStream as: fileNameOnServer] - [client putFileStreamContents: fileStream as: fileNameOnServer] ensure: [self quit]! Item was added: + ----- Method: ServerDirectory>>entryAt:ifAbsent: (in category 'file directory') ----- + entryAt: fileName ifAbsent: aBlock + "Find the entry with local name fileName and answer it. + If not found, answer the result of evaluating aBlock." + ^ self entries + detect: [ : entry | entry name = fileName ] + ifNone: aBlock! |
Free forum by Nabble | Edit this page |