Creates a hard link to the target file in the vault directory
            and saves information about the target file in the database
423867
def secure(self):
        '''
            
        '''
        verbose('Saving information about target into conman database')
        self._id = self.db.insertTarget(self.name, self.path)

        verbose('Creating a hard link from {} to {} directory'.format(
            str(self), config.CONMAN_PATH   
        ))
        link(self.real_path, self.vault_path)
672066
def _create_target_dir_if_needed(self, target, depth_limit=20):
        """"""

        if depth_limit <= 0:
            raise FtpCreateDirsException('Depth limit exceeded')
        if not target:
            return
        target_dir = os.path.dirname(target)
        parent_dir, dir_name = os.path.split(target_dir)

        parent_dir_ls = []
        try:
            parent_dir_ls = self.ftp.nlst(parent_dir)
        except:
            # Possibly a microsoft server
            # They throw exceptions when we try to ls non-existing folders
            pass

        parent_dir_files = [os.path.basename(d) for d in parent_dir_ls]
        if dir_name not in parent_dir_files:
            if parent_dir and target_dir != '/':
                self._create_target_dir_if_needed(target_dir, depth_limit=depth_limit - 1)

            self.logger.info('Will create dir: %s' % target)
            self.ftp.mkd(target_dir)
930022
def _latch_file_info(self):
        
        self._map_arguments(self.args)
        self.files.latch_file_info(self.args)
        self.sub_files.file_dict.clear()
        self.sub_files.update(self.files.file_dict)
        for link in self._links.values():
            self.sub_files.update(link.files.file_dict)
            self.sub_files.update(link.sub_files.file_dict)
618442
function buildFromDirectory(dirPath){
	var dbsetPath = path.join(dirPath,"dbsets");
	if(fileutil.isExist(dbsetPath)){
		defaultConfig['dbsets'] = dbsetPath;
	}

	var stubsPath = path.join(dirPath,"stubs");
	if(fileutil.isExist(stubsPath)){
		defaultConfig['stubs'] = stubsPath;
	}

	var dumpsPath = path.join(dirPath,"dumps");
	if(fileutil.isExist(dumpsPath)){
		defaultConfig['dumps'] = dumpsPath;
	}

	var mappingsPath = path.join(dirPath,"mappings");
	var files = fileutil.ls(mappingsPath);
	if(files.length > 0){
		defaultConfig['mappings']['requests'] = [];
		files.forEach(function(filename){
			defaultConfig['mappings']['requests'].push(path.join(mappingsPath , filename));
		});
	}

	var trustStorePath = path.join(dirPath,"truststore");
	if(fileutil.isExist(trustStorePath)){
		defaultConfig.server.key = path.join(trustStorePath , "server.key");
		defaultConfig.server.cert = path.join(trustStorePath , "server.crt");

		var cacertPath = path.join(trustStorePath,"ca");
		var cacerts = fileutil.ls(cacertPath);

		if(cacerts.length > 0){
			defaultConfig.server.ca = [];
			cacerts.forEach(function(filename){
				defaultConfig.server.ca.push(path.join(cacertPath , filename));
			});
		}
	}
}
219105
def write_raw(path, raw):
    '''
    
    '''
    log.debug('Writing vault secrets for %s at %s', __grains__['id'], path)
    try:
        url = 'v1/{0}'.format(path)
        response = __utils__['vault.make_request']('POST', url, json=raw)
        if response.status_code == 200:
            return response.json()['data']
        elif response.status_code != 204:
            response.raise_for_status()
        return True
    except Exception as err:
        log.error('Failed to write secret! %s: %s', type(err).__name__, err)
        return False
764945
function createStatEntry(file, fullpath, callback) {
        fs.lstat(fullpath, function (err, stat) {
            var entry = {
                name: file
            };

            if (err) {
                entry.err = err;
                return callback(entry);
            } else {
                entry.size = stat.size;
                entry.mtime = stat.mtime.valueOf();

                if (stat.isDirectory()) {
                    entry.mime = "inode/directory";
                } else if (stat.isBlockDevice()) entry.mime = "inode/blockdevice";
                else if (stat.isCharacterDevice()) entry.mime = "inode/chardevice";
                else if (stat.isSymbolicLink()) entry.mime = "inode/symlink";
                else if (stat.isFIFO()) entry.mime = "inode/fifo";
                else if (stat.isSocket()) entry.mime = "inode/socket";
                else {
                    entry.mime = getMime(fullpath);
                }

                if (!stat.isSymbolicLink()) {
                    return callback(entry);
                }
                fs.readlink(fullpath, function (err, link) {
                    if (entry.name == link) {
                        entry.linkStatErr = "ELOOP: recursive symlink";
                        return callback(entry);
                    }

                    if (err) {
                        entry.linkErr = err.stack;
                        return callback(entry);
                    }
                    entry.link = link;
                    resolvePath(pathResolve(dirname(fullpath), link), {alreadyRooted: true}, function (err, newpath) {
                      if (err) {
                          entry.linkStatErr = err;
                          return callback(entry);
                      }
                      createStatEntry(basename(newpath), newpath, function (linkStat) {
                          entry.linkStat = linkStat;
                          linkStat.fullPath = newpath.substr(base.length) || "/";
                          return callback(entry);
                      });
                    });
                });
            }
        });
    }
292812
def delete(self):
        '''
            
        '''
        if not self._id:
            verbose('This target does not have an id')
            return False

        # Removes link from vault directory
        verbose('Removing link from vault directory')
        os.remove(self.vault_path)

        verbose('Removing information from database')
        # Removing information from database
        self.db.removeTarget(self._id) 
        self._id = -1

        return True
984641
def symlink_to(self, target, target_is_directory=False):
        
        if self._closed:
            self._raise_closed()
        self._accessor.symlink(target, self, target_is_directory)
266306
def create
      @share_link = @file.share_links.build(permitted_params.share_link)
      @share_link.user = boxroom_current_user

      if @share_link.save
        UserMailer.share_link_email(@share_link).deliver_now
        redirect_to @folder, :notice => t(:shared_successfully)
      else
        render :action => 'new'
      end
    end
708186
def to_filelink(self):
        
        if self.status != 'completed':
            return 'Audio/video conversion not complete!'

        response = utils.make_call(self.url, 'get')

        if response.ok:
            response = response.json()
            handle = re.match(
                r'(?:https:\/\/cdn\.filestackcontent\.com\/)(\w+)',
                response['data']['url']
            ).group(1)
            return filestack.models.Filelink(handle, apikey=self.apikey, security=self.security)

        raise Exception(response.text)
510946
def _store_path(self, filepath, fprogress):
        """"""
        st = os.lstat(filepath)     # handles non-symlinks as well
        if S_ISLNK(st.st_mode):
            # in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8
            open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), encoding=defenc))
        else:
            open_stream = lambda: open(filepath, 'rb')
        with open_stream() as stream:
            fprogress(filepath, False, filepath)
            istream = self.repo.odb.store(IStream(Blob.type, st.st_size, stream))
            fprogress(filepath, True, filepath)
        return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
                               istream.binsha, 0, to_native_path_linux(filepath)))
520136
def deploy_file(self,
                    file_name,
                    calc_md5=True,
                    calc_sha1=True,
                    parameters={}):
        
        if calc_md5:
            md5 = md5sum(file_name)
        if calc_sha1:
            sha1 = sha1sum(file_name)

        target = self

        if self.is_dir():
            target = self / pathlib.Path(file_name).name

        with open(file_name, 'rb') as fobj:
            target.deploy(fobj, md5, sha1, parameters)
938553
def _save_payload(self, files, directories, links):
        '''
        
        '''

        idx = 0
        for p_type, p_list in (('f', files), ('d', directories), ('l', links,),):
            for p_obj in p_list:
                stats = os.stat(p_obj)

                payload = PayloadFile()
                payload.id = idx
                payload.path = p_obj
                payload.p_type = p_type
                payload.mode = stats.st_mode
                payload.uid = stats.st_uid
                payload.gid = stats.st_gid
                payload.p_size = stats.st_size
                payload.atime = stats.st_atime
                payload.mtime = stats.st_mtime
                payload.ctime = stats.st_ctime

                idx += 1
                self.db.store(payload)
160822
def hardlink(source, link_name):
    
    if sys.version_info < (3,) and platform.system() == 'Windows':  # pragma: no cover
        import ctypes
        create_hard_link = ctypes.windll.kernel32.CreateHardLinkW
        create_hard_link.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_void_p]
        create_hard_link.restype = ctypes.wintypes.BOOL
        res = create_hard_link(link_name, source, None)
        if res == 0:
            raise ctypes.WinError()
    else:
        try:
            os.link(source, link_name)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
            else:
                # It's possible that the user created a different file with the same name as the
                # one we're trying to download. Thus we need to check the if the inode is different
                # and raise an error in this case.
                source_stat = os.stat(source)
                dest_stat = os.stat(link_name)
                # Check device first because different drives can have the same inode number
                if source_stat.st_dev != dest_stat.st_dev or source_stat.st_ino != dest_stat.st_ino:
                    raise
220825
public static void link(File src, File dst) throws IOException {
    if (src == null || dst == null) {
      throw new IllegalArgumentException("Null parameter passed");
    }
    if (isAvailable()) {
      link(src.getAbsolutePath(), dst.getAbsolutePath());
    } else {
      HardLink.createHardLink(src, dst);
    }
  }
844050
def attach_related_file(self, path, mimetype=None):
        """"""
        filename = os.path.basename(path)
        content = open(path, 'rb').read()
        self.attach_related(filename, content, mimetype)
333147
def _make_symlink(self, link_name: str, link_target: str):
        ''''''
        path = self._file_writer_session.extra_resource_path('dummy')

        if path:
            dir_path = os.path.dirname(path)
            symlink_path = os.path.join(dir_path, link_name)

            _logger.debug('symlink {} -> {}', symlink_path, link_target)

            os.symlink(link_target, symlink_path)

            _logger.info(
                _('Created symbolic link {symlink_path} to target {symlink_target}.'),
                symlink_path=symlink_path,
                symlink_target=link_target
            )