<commit_before>/*
 * Copyright (c) 2012-2013 Stanford University
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>

#define FUSE_USE_VERSION 26
#include <fuse.h>

#include <string>
#include <map>
#include <algorithm>
#include <boost/tr1/memory.hpp>
#include <oriutil/oritr1.h>

#include <oriutil/debug.h>
#include <oriutil/orifile.h>
#include <oriutil/scan.h>
#include <oriutil/systemexception.h>
#include <oriutil/rwlock.h>
#include <oriutil/objecthash.h>
#include <ori/commit.h>
#include <ori/localrepo.h>
#include <ori/treediff.h>

#include "logging.h"
#include "oricmd.h"
#include "oripriv.h"
#include "oriopt.h"
#include "server.h"

using namespace std;
using namespace std::tr1;

// XXX: Hacky remove dependence
extern mount_ori_config config;

void
OriFileInfo::loadAttr(const AttrMap &attrs)
{
    struct passwd *pw = getpwnam(attrs.getAsStr(ATTR_USERNAME).c_str());

    if (pw == NULL) {
      pw = getpwuid(getuid());
    }

    if (statInfo.st_mode != S_IFDIR) {
        bool isSymlink = false;

        if (attrs.has(ATTR_SYMLINK)) {
            isSymlink = attrs.getAs<bool>(ATTR_SYMLINK);
        }
    
        if (isSymlink) {
            statInfo.st_mode = S_IFLNK;
            statInfo.st_nlink = 1;
        } else {
            statInfo.st_mode = S_IFREG;
            statInfo.st_nlink = 1;
        }
    }

    statInfo.st_mode |= attrs.getAs<mode_t>(ATTR_PERMS);
    statInfo.st_uid = pw->pw_uid;
    statInfo.st_gid = pw->pw_gid;
    statInfo.st_size = attrs.getAs<size_t>(ATTR_FILESIZE);
    statInfo.st_blocks = (statInfo.st_size + 511) / 512;
    statInfo.st_mtime = attrs.getAs<time_t>(ATTR_MTIME);<commit_msg>NOT_IMPLEMENTED check for null pw<commit_after>/*
 * Copyright (c) 2012-2013 Stanford University
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>

#define FUSE_USE_VERSION 26
#include <fuse.h>

#include <string>
#include <map>
#include <algorithm>
#include <boost/tr1/memory.hpp>
#include <oriutil/oritr1.h>

#include <oriutil/debug.h>
#include <oriutil/orifile.h>
#include <oriutil/scan.h>
#include <oriutil/systemexception.h>
#include <oriutil/rwlock.h>
#include <oriutil/objecthash.h>
#include <ori/commit.h>
#include <ori/localrepo.h>
#include <ori/treediff.h>

#include "logging.h"
#include "oricmd.h"
#include "oripriv.h"
#include "oriopt.h"
#include "server.h"

using namespace std;
using namespace std::tr1;

// XXX: Hacky remove dependence
extern mount_ori_config config;

void
OriFileInfo::loadAttr(const AttrMap &attrs)
{
    struct passwd *pw = getpwnam(attrs.getAsStr(ATTR_USERNAME).c_str());

    if (pw == NULL) {
      pw = getpwuid(getuid());
      NOT_IMPLEMENTED(pw != NULL);
    }

    if (statInfo.st_mode != S_IFDIR) {
        bool isSymlink = false;

        if (attrs.has(ATTR_SYMLINK)) {
            isSymlink = attrs.getAs<bool>(ATTR_SYMLINK);
        }
    
        if (isSymlink) {
            statInfo.st_mode = S_IFLNK;
            statInfo.st_nlink = 1;
        } else {
            statInfo.st_mode = S_IFREG;
            statInfo.st_nlink = 1;
        }
    }

    statInfo.st_mode |= attrs.getAs<mode_t>(ATTR_PERMS);
    statInfo.st_uid = pw->pw_uid;
    statInfo.st_gid = pw->pw_gid;
    statInfo.st_size = attrs.getAs<size_t>(ATTR_FILESIZE);
    statInfo.st_blocks = (statInfo.st_size + 511) / 512;
    statInfo.st_mtime = attrs.getAs<time_t>(ATTR_MTIME);
{'fraction_non_alphanumeric': 0.11551416683178126, 'fraction_numerical': 0.008321775312066574, 'mean_word_length': 3.6142595978062158, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2527830', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1729, 'n_words': 481}