Metacello / metacello

Metacello is a package management system for Smalltalk
MIT License
87 stars 43 forks source link

MCGitBasedNetworkRepository >> flushCache fails to `flush` if permission issues on directory exist #376

Closed dalehenrich closed 9 years ago

dalehenrich commented 9 years ago

Related to Issue #375.

From Mariano:

Problem is that even if I do  `MCGitHubRepository cacheDirectory: nil`  the MCGitHubRepository instances still have the offending directory as part of the instvar 'directory' and so the MC load fails. That's why I think I need this code:

    MCRepositoryGroup default repositoriesDo: [:rep | rep flushCache ].

Which effectively clears the 'directory' from the MCGitHubRepository instances. But..guess what? I cannot flush, because:

MCGitBasedNetworkRepository >> flushCache
  "the directory acts like a cache since we download the directory from a git-based repository (github, bitbucket, etc.)"

  super flushCache.
  self class flushDownloadCache.
  directory := nil

that method calls super and so this is executed:

MCFileTreeRepository >> flushCache
  "force properties to be reread ... if the directory exists, otherwise let nature
   take it's course"

  super flushCache.
  directory
    ifNotNil: [ 
      (MCFileTreeFileUtils current directoryExists: directory)   ->>> this will throw error now
        ifTrue: [ 
          repositoryProperties := nil.
          self repositoryProperties ] ]

So...to conclude, THIS piece of code does seem to workaround my problem:

MCGitHubRepository cacheDirectory: nil.
System commit. 
MCGitBasedNetworkRepository allSubInstances do: [ :rep | 
      " cannot send #directory: becaue it really expects a directory instance. 
      By puttin a nil in 'directory' we are able to run #flushCache. See MCFileTreeRepository >> flushCache.  for more details  "
      rep instVarNamed: 'directory' put: nil.
      rep flushCache ].
System commit. 
dalehenrich commented 9 years ago

This problem should be fixed ... we can unconditionally clear the directory entry if an error occurs ...

dalehenrich commented 9 years ago

Proposed fix to MCGitBasedNetworkRepository >> flushCache:

flushCache
  "the directory acts like a cache since we download the directory from a git-based repository (github, bitbucket, etc.)"

  [super flushCache] on: Error do: [:ignored | "perhaps dump something to Transcript?" ].
  self class flushDownloadCache.
  directory := nil
dalehenrich commented 9 years ago

Mariano suggests logging to Transcript:

flushCache
  "the directory acts like a cache since we download the directory from a git-based repository (github, bitbucket, etc.)"

  [ super flushCache ]
    on: Error
    do: [ :ex |
      Transcript
        cr;
        show:
            'Error for: ' , self description printString , ' during flushCache: '
                , ex description printString ].
  self class flushDownloadCache.
  directory := nil