Restrict copy source code into snap packages

i m working on ubuntu core 16 and i build snap packages but the problem is my source code are also present in snap packages and i don’t want this. so what the solution is ???


This depends on what language your source code is written in. Snaps do nothing to help you or hinder you from hiding your code. If your code is visible in other distribution formats then it will be visible in a snap in the same way.

If it is Python for example then you cannot hide it because Python needs to read the source every time it executes. The same is true for any scripting language.

If your code is compiled from C or Rust or go or similar then you need to just not copy the source into your snap. You’ll need to show us your snapcraft.yaml and give us a description of your project’s layout for us to advise how to do that.

Thanks Daniel,
My source code written in C++ and my .yaml file looks like this,

name: gatewayapp # you probably want to 'snapcraft register ’
version: ‘1.0.5’ # 1-Jul-2019. Set UV as average and wait for read as per the data fetch interval in config files.
summary: This is a gateway application # 79 char long summary
description: |
Set UV as average and wait for read as per the data fetch interval in config files.

grade: devel # must be ‘stable’ to release into candidate/stable channels
confinement: devmode # use ‘strict’ once you have the right plugs and slots

command: bin/GatewayApp

plugin: cmake

source: .

after: [gateway-app]
plugin: dump
source: .


The reason your source code is included is because of your part called hook, which is specified to use the dump plugin with source: . meaning dump everything from your project folder into the root of your snap.

What is this part trying to achieve? If you want to include snap hooks they should be placed into snap/hooks/$hookname where they’ll automatically be added to your snap without requiring any specific part definition to add them.

Thanks for the valuable response.

Actually I want to make one folder and copy some files into /var/snap so that purpose I used Hook(in this ./configure i make one folder and copy some files ).

here i do not copy hook part into /snap/hooks directly.
Here hook is a part of source so that’s way I add source
any other way to doing this operation.

There’s several things you can do, which you can choose from:

  1. You could move the files you want to copy into a subfolder specific for those files inside your project and change source: . to source: sub-folder-name.
  2. Use the stage or prime keywords to remove the source files when snapcraft performs those steps (either keyword will achieve the same result) reference:
  3. Add an override-pull scriptlet to the hook part that copies just the files you want from $SNAPCRAFT_PROJECT_DIR to $SNAPCRAFT_PART_SRC.
1 Like

Thank u so much.
I think this is help me a lot.