@@ -128,12 +128,25 @@ Lambda.prototype._zip = function(program, codeDirectory, callback) {
128128 zip . file ( file , content ) ;
129129 }
130130 } ) ;
131-
131+
132132 var data = zip . generate ( options ) ;
133133
134134 return callback ( null , data ) ;
135135} ;
136136
137+ Lambda . prototype . _nativeZip = function ( program , codeDirectory , callback ) {
138+ var zipfile = this . _zipfileTmpPath ( program )
139+ , cmd = 'zip -r ' + zipfile + ' .'
140+ , run = exec ( cmd , { cwd : codeDirectory } , function ( err , stdout , stderr ) {
141+ if ( err !== null ) {
142+ return callback ( err , null )
143+ }
144+
145+ var data = fs . readFileSync ( zipfile )
146+ callback ( null , data )
147+ } )
148+ } ;
149+
137150Lambda . prototype . _codeDirectory = function ( program ) {
138151 var epoch_time = + new Date ;
139152 return os . tmpDir ( ) + '/' + program . functionName + '-' + epoch_time ;
@@ -149,7 +162,11 @@ Lambda.prototype.deploy = function(program) {
149162 // Move all files to tmp folder (except .git, .log, event.json and node_modules)
150163 _this . _rsync ( program , codeDirectory , function ( err , result ) {
151164 _this . _npmInstall ( program , codeDirectory , function ( err , result ) {
152- _this . _zip ( program , codeDirectory , function ( err , buffer ) {
165+ // Use zip from the command line on non-windows systems to preserve file permissions
166+ var archive = process . platform != 'win32' ? _this . _nativeZip : _this . _zip ;
167+ archive = archive . bind ( _this )
168+
169+ archive ( program , codeDirectory , function ( err , buffer ) {
153170
154171 console . log ( 'Reading zip file to memory' ) ;
155172 //var buffer = fs.readFileSync(zipfile);
0 commit comments