Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33b2264e authored by Kenny Root's avatar Kenny Root
Browse files

Move disk usage utilities to its own library

Disk usage calculation will happen in more places now, so move the
installd calculation utilities out to its own library that only gets
built for the target.

Change-Id: Idceb6bd663ca6ab3d38fa00e57ee74a25b784855
parent 0b44476a
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -6,16 +6,19 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
    installd.c commands.c utils.c

LOCAL_C_INCLUDES := \
    $(call include-path-for, system-core)/cutils
#LOCAL_C_INCLUDES := \
#    $(call include-path-for, system-core)/cutils

LOCAL_SHARED_LIBRARIES := \
    libcutils

LOCAL_STATIC_LIBRARIES :=
LOCAL_STATIC_LIBRARIES := \
    libdiskusage

LOCAL_MODULE := installd

LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)

endif # !simulator))
endif # !simulator
+1 −49
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
*/

#include "installd.h"
#include <diskusage/dirsize.h>

int install(const char *pkgname, int encrypted_fs_flag, uid_t uid, gid_t gid)
{
@@ -327,55 +328,6 @@ int protect(char *pkgname, gid_t gid)
    return 0;
}

static int64_t stat_size(struct stat *s)
{
    int64_t blksize = s->st_blksize;
    int64_t size = s->st_size;

    if (blksize) {
            /* round up to filesystem block size */
        size = (size + blksize - 1) & (~(blksize - 1));
    }

    return size;
}

static int64_t calculate_dir_size(int dfd)
{
    int64_t size = 0;
    struct stat s;
    DIR *d;
    struct dirent *de;

    d = fdopendir(dfd);
    if (d == NULL) {
        close(dfd);
        return 0;
    }

    while ((de = readdir(d))) {
        const char *name = de->d_name;
        if (de->d_type == DT_DIR) {
            int subfd;
                /* always skip "." and ".." */
            if (name[0] == '.') {
                if (name[1] == 0) continue;
                if ((name[1] == '.') && (name[2] == 0)) continue;
            }
            subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
            if (subfd >= 0) {
                size += calculate_dir_size(subfd);
            }
        } else {
            if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
                size += stat_size(&s);
            }
        }
    }
    closedir(d);
    return size;
}

int get_size(const char *pkgname, const char *apkpath,
             const char *fwdlock_apkpath,
             int64_t *_codesize, int64_t *_datasize, int64_t *_cachesize, int encrypted_fs_flag)
+30 −0
Original line number Diff line number Diff line
/*
 *
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __LIBDISKUSAGE_DIRSIZE_H
#define __LIBDISKUSAGE_DIRSIZE_H

#include <stdint.h>

__BEGIN_DECLS

int64_t stat_size(struct stat *s);
int64_t calculate_dir_size(int dfd);

__END_DECLS

#endif /* __LIBDISKUSAGE_DIRSIZE_H */
+24 −0
Original line number Diff line number Diff line
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := libdiskusage

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := dirsize.c

include $(BUILD_STATIC_LIBRARY)
 No newline at end of file
+0 −0

Empty file added.

Loading