Example #1
0
                .map(function (_path) {
                    var ext = path.extname(_path),
                        name = path.basename(_path, ext),
                        stat;

                    try {
                        stat = fs.statSync(_path);
                    } catch (e) {
                        switch (e.code) {
                        case 'EACCES':
                        case 'EPERM':
                        case 'EBUSY':
                            stat = { isDirectory: function () {} };
                            break;
                        default:
                            throw e;
                        }
                    }

                    return {
                        path: _path,
                        filename: path.basename(_path),
                        name: name, // @todo redundant
                        ext: ext.substr(1), // @todo redundant
                        size: stat.isDirectory() ? undefined : stat.size,
                        isDirectory: stat.isDirectory(),
                        lastChanged: stat.ctime,
                        lastAccessed: stat.atime,
                        lastModified: stat.mtime
                    };
                })
export default function isDirectory(filePath) {
  try {
    return statSync(filePath).isDirectory();
  } catch (e) {
    return false;
  }
}
Example #3
0
 this.refs.image.onload = () => {
   this.refs.image.onload = null
   this.originalHeight = this.refs.image.naturalHeight
   this.originalWidth = this.refs.image.naturalWidth
   this.imageSize = fs.statSync(this.editor.getPath()).size
   this.emitter.emit('did-update')
 }
Example #4
0
function isNewPathValid(previousPath, nextPath) {
  if (!isFileSync(nextPath)) return true;

  /*
  New path exists so check if it points to the same file as the initial
  path to see if the case of the file name is being changed on a on a
  case insensitive filesystem.
  */
  const oldStat = statSync(previousPath);
  const newStat = statSync(nextPath);
  const haveSamePath = previousPath.toLowerCase() === nextPath.toLowerCase();
  const haveSameDev = oldStat.dev === newStat.dev;
  const haveSameIno = oldStat.ino === newStat.ino;

  return !(haveSamePath && haveSameDev && haveSameIno);
}
export default function fileExists(filePath) {
  try {
    statSync(filePath);
  } catch (e) {
    if (e.code === 'ENOENT') return false;
  }
  return true;
}
Example #6
0
function isDirectory(dirPath) {
  let isDir
  try {
    isDir = fs.statSync(dirPath).isDirectory()
  } catch (e) {
    isDir = false
  }
  return isDir
}
Example #7
0
  // Internal: Takes filename and runs callbacks.update with file details.
  //
  // filename - String filename
  //
  function update(filename) {
    var documentPath = path + "/" + filename;
    var stats = fs.statSync(documentPath);

    callbacks.update({
      filename: filename,
      modifiedAt: stats.mtime.getTime(),
      body: fs.readFileSync(documentPath, {encoding: "utf8"})
    });
  }
Example #8
0
				lis.forEach(function (name) {
					if (name == '.' || name == '..')
						return;

					name = Path.join(p, name);
					var stats = FS.statSync(name);
					list.push({
						name: name,
						size: stats.size,
						date: stats.mtime,
						type: stats.isFile() ? 'f' : 'd'
					});
					if (!stats.isFile()) {
						l(name);
					}
				});
Example #9
0
						var n = function () {
							if (++i >= list.length)
								return e();
							var item = list[i],
								remote = self.client.toRemote(item.name);
							if (item.type == 'd' || item.type == 'l') {
								self.ftp.mkdir(remote, function (err) {
									if (err)
										error = err;
									return n();
								});
							} else {
								var stats = FS.statSync(item.name);
								size = stats.size;
								written = 0;
								self.ftp.put(item.name, remote, function (err) {
									if (err)
										error = err;
									return n();
								});
							}
						};
Example #10
0
	ConnectorFTP.prototype.put = function (path, completed, progress) {
		var self = this,
			remote = self.client.toRemote(path);

		if (self.isConnected()) {
			// File
			if (FS.isFileSync(path)) {
				var stats = FS.statSync(path),
					size = stats.size,
					written = 0,
					pool;
				var e = function (err) {
					if (typeof completed === 'function')
						completed.apply(null, [err ? err : null, [{name: path, type: 'f'}]]);
				};
				pool = setInterval(function () {
					if (!self.ftp || !self.ftp._pasvSocket) return;
					written = self.ftp._pasvSocket.bytesWritten;
					if (typeof progress === 'function')
						progress.apply(null, [written / size]);
				}, 250);
				self.ftp.put(path, remote, function (err) {
					if (err) {
						self.mkdir(Path.dirname(remote).replace(/\\/g, '/'), true, function (err) {
							self.ftp.put(path, remote, function (err) {
								if (pool)
									clearInterval(pool);
								return e(err);
							});
						});
						return;
					}
					if (pool)
						clearInterval(pool);
					return e();
				});
			}

			// Folder
			else {
				self.client._traverseTree(path, function (list) {
					self.mkdir(remote, true, function (err) {
						var error,
							i = -1,
							total = list.length,
							size = 0,
							written = 0,
							pool = setInterval(function () {
								if (!self.ftp || !self.ftp._pasvSocket) return;
								written = self.ftp._pasvSocket.bytesWritten;
								if (typeof progress === 'function')
									progress.apply(null, [(i / total) + (written / size / total)]);
							}, 250);
						var e = function () {
							if (pool)
								clearInterval(pool);
							if (typeof completed === 'function')
								completed.apply(null, [error, list]);
						};
						var n = function () {
							if (++i >= list.length)
								return e();
							var item = list[i],
								remote = self.client.toRemote(item.name);
							if (item.type == 'd' || item.type == 'l') {
								self.ftp.mkdir(remote, function (err) {
									if (err)
										error = err;
									return n();
								});
							} else {
								var stats = FS.statSync(item.name);
								size = stats.size;
								written = 0;
								self.ftp.put(item.name, remote, function (err) {
									if (err)
										error = err;
									return n();
								});
							}
						};
						return n();
					});
				});
			}
		}
		else {
			if (typeof completed === 'function')
				completed.apply(null, ['Not connected']);
		}

		return self;
	};
Example #11
0
        self.sftp.stat(remotePath, (err, attrs) => {
          const options = {};

          if (self.customFilePermissions) {
                          // overwrite permissions when filePermissions option set
            options.mode = parseInt(self.customFilePermissions, 8);
          } else if (err) {
                          // using the default 0644
            options.mode = 0o0644;
          } else {
                          // using the original permissions from the remote
            options.mode = attrs.mode;
          }

          const readStream = FS.createReadStream(localPath);
          const writeStream = self.sftp.createWriteStream(remotePath, options);
          const fileSize = FS.statSync(localPath).size; // used for setting progress bar
          let totalRead = 0; // used for setting progress bar


          function applyProgress() {
            if (typeof progress !== 'function') return;
            if (total != null && i != null) {
              progress(...[(i / total) + (totalRead / fileSize / total)]);
            } else {
              progress(...[totalRead / fileSize]);
            }
          }


          writeStream
                      .on('finish', () => {
    applyProgress(); // completes the progress bar
    return e();
  })
                      .on('error', (err) => {
    if (!obj.hasOwnProperty('err') && (err.message == 'No such file' || err.message === 'NO_SUCH_FILE')) {
      self.mkdir(Path.dirname(remote).replace(/\\/g, '/'), true, (err) => {
        if (err) {
          const error = err.message || err;
          atom.notifications.addError(`Remote FTP: Upload Error ${error}`, {
            dismissable: false,
          });
          return err;
        }
        put(Object.assign({}, obj, { err }));
      });
    } else {
      const error = err.message || err;
      atom.notifications.addError(`Remote FTP: Upload Error ${error}`, {
        dismissable: false,
      });
    }
  });

          readStream
                      .on('data', (chunk) => {
    totalRead += chunk.length;
    if (totalRead === fileSize) return; // let writeStream.on("finish") complete the progress bar
    applyProgress();
  });

          readStream.pipe(writeStream);
        });
Example #12
0
  deactivate () {
    this.subscriptions.dispose()
    return this.autosaveAllPaneItems()
  },

  autosavePaneItem (paneItem, create = false) {
    if (!atom.config.get('autosave.enabled')) return
    if (!paneItem) return
    if (typeof paneItem.getURI !== 'function' || !paneItem.getURI()) return
    if (typeof paneItem.isModified !== 'function' || !paneItem.isModified()) return
    if (typeof paneItem.getPath !== 'function' || !paneItem.getPath()) return
    if (!shouldSave(paneItem)) return

    try {
      const stats = fs.statSync(paneItem.getPath())
      if (!stats.isFile()) return
    } catch (e) {
      if (e.code !== 'ENOENT') return
      if (!create) return
    }

    const pane = atom.workspace.paneForItem(paneItem)
    let promise = Promise.resolve()
    if (pane) {
      promise = pane.saveItem(paneItem)
    } else if (typeof paneItem.save === 'function') {
      promise = paneItem.save()
    }
    return promise
  },
Example #13
0
  constructor (editor) {
    this.editor = editor
    this.emitter = new Emitter()
    this.disposables = new CompositeDisposable()
    this.imageSize = fs.statSync(this.editor.getPath()).size
    this.loaded = false
    this.mode = 'zoom-to-fit'
    this.percentageStep = 4
    this.steps = [0.1, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2, 3, 4, 5, 7.5, 10]
    etch.initialize(this)

    this.refs.image.style.display = 'none'
    this.updateImageURI()

    this.disposables.add(this.editor.onDidChange(() => this.updateImageURI()))
    this.disposables.add(atom.commands.add(this.element, {
      'image-view:reload': () => this.updateImageURI(),
      'image-view:zoom-in': () => this.zoomIn(),
      'image-view:zoom-out': () => this.zoomOut(),
      'image-view:zoom-to-fit': () => this.zoomToFit(),
      'image-view:reset-zoom': () => this.resetZoom(),
      'core:move-up': () => { this.scrollUp() },
      'core:move-down': () => { this.scrollDown() },
      'core:page-up': () => { this.pageUp() },
      'core:page-down': () => { this.pageDown() },
      'core:move-to-top': () => { this.scrollToTop() },
      'core:move-to-bottom': () => { this.scrollToBottom() }
    }))

    this.refs.image.onload = () => {
      this.refs.image.onload = null
      this.originalHeight = this.refs.image.naturalHeight
      this.originalWidth = this.refs.image.naturalWidth
      this.loaded = true
      this.refs.image.style.display = ''
      this.defaultBackgroundColor = atom.config.get('image-view.defaultBackgroundColor')
      this.refs.imageContainer.setAttribute('background', this.defaultBackgroundColor)
      this.emitter.emit('did-load')
    }

    this.disposables.add(atom.tooltips.add(this.refs.whiteTransparentBackgroundButton, {title: 'Use white transparent background'}))
    this.disposables.add(atom.tooltips.add(this.refs.blackTransparentBackgroundButton, {title: 'Use black transparent background'}))
    this.disposables.add(atom.tooltips.add(this.refs.transparentTransparentBackgroundButton, {title: 'Use transparent background'}))

    const clickHandler = (event) => {
      event.preventDefault()
      event.stopPropagation()
      this.changeBackground(event.target.value)
    }

    this.refs.whiteTransparentBackgroundButton.addEventListener('click', clickHandler)
    this.disposables.add(new Disposable(() => { this.refs.whiteTransparentBackgroundButton.removeEventListener('click', clickHandler) }))
    this.refs.blackTransparentBackgroundButton.addEventListener('click', clickHandler)
    this.disposables.add(new Disposable(() => { this.refs.blackTransparentBackgroundButton.removeEventListener('click', clickHandler) }))
    this.refs.transparentTransparentBackgroundButton.addEventListener('click', clickHandler)
    this.disposables.add(new Disposable(() => { this.refs.transparentTransparentBackgroundButton.removeEventListener('click', clickHandler) }))

    const zoomInClickHandler = () => {
      this.zoomIn()
    }
    this.refs.zoomInButton.addEventListener('click', zoomInClickHandler)
    this.disposables.add(new Disposable(() => { this.refs.zoomInButton.removeEventListener('click', zoomInClickHandler) }))

    const zoomOutClickHandler = () => {
      this.zoomOut()
    }
    this.refs.zoomOutButton.addEventListener('click', zoomOutClickHandler)
    this.disposables.add(new Disposable(() => { this.refs.zoomOutButton.removeEventListener('click', zoomOutClickHandler) }))

    const resetZoomClickHandler = () => {
      this.resetZoom()
    }
    this.refs.resetZoomButton.addEventListener('click', resetZoomClickHandler)
    this.disposables.add(new Disposable(() => { this.refs.resetZoomButton.removeEventListener('click', resetZoomClickHandler) }))

    const zoomToFitClickHandler = () => {
      this.zoomToFit()
    }
    this.refs.zoomToFitButton.addEventListener('click', zoomToFitClickHandler)
    this.disposables.add(new Disposable(() => { this.refs.zoomToFitButton.removeEventListener('click', zoomToFitClickHandler) }))
  }